Overview
This article includes some ideas for capturing the user who completed a state change in a workflow.
Solution
This article expands a little on the discussion in M-Files community, where two options are presented.
https://community.m-files.com/index.php?topic=8796.msg22764
First option is to iterate over the object's history until you find the change you're interested in, and retrieve the last modified by ID at that point
A possibly simpler option is to use scripting to log to a property value the current user at the point it's moved into the state. There are several ways to go about this, but to give some ideas and a template to work with, the following script can be attached to beforecheckinchanges event handler.
NOTE: this is just a sample and is by no means meant to be production ready, just something to get started with. For example, production scripts should use aliases to identify properties and states.
In this sample there is a state called "Loggedstate" that should log the user property. The property is set to a "select from list users" property (ID 1238)
Option explicit
dim statetext
Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer, False)
statetext = PropertyValues.SearchForProperty(39).GetValueAsUnlocalizedText
if statetext = "Loggedstate" then
' Set workflow assignment property
Dim oPropVal: Set oPropVal = CreateObject("MFilesAPI.PropertyValue")
oPropVal.PropertyDef = 1238
oPropVal.TypedValue.SetValue MFDatatypeLookup, CurrentUserID
Call Vault.ObjectPropertyOperations.SetProperty(ObjVer, oPropVal)
end if
