ChooseUser()
This code sample describes how to identify the user to which the next step in a workflow is assigned.
Function Integer ChooseUser( \
Object prgCtx, \
WAPIWORK work, \
Integer workID, \
Integer subWorkID, \
Integer taskID, \
Integer returnSubWorkID, \
Integer returnTaskID, \
Integer performerID = Undefined )
//The following variable declarations are taken from the
//prototype for performer event trigger scripts. This
//information is stored in the ODocumentation() script associated
//with the PerformerCallbackScripts object in your custom module.
Dynamic userID
RecArray attribs
RecArray performer
Record r
String userName
Boolean found = False
Boolean success = True
//The following variable declaration references the attributes
//API object. This object contains the scripts that store data in
//the database, retrieve data from the database, and delete data
//in the database. All of the different types of data that pass
//through a workflow have an attributes API object. The
//attributes API objects are all children or orphans of
//WFMain:WFRoot:WFObjectTypes:WFDataTypes.
Object obj = $WFMain.WFPackageSubsystem.GetItemByName( \
'WFAttributes' )
Object uSession = prgCtx.USession()
Object wSession = prgCtx.WSession()
//Call the script that loads the different types of data that are
//flowing through the workflow (for example, comments,
//attachments, forms, attributes).
RecArray array = $WFMain.WAPIPkg.LoadWorkData( prgCtx, work )
//Walk through all the different types of data that are flowing
//through this workflow, (for example, comments, attachments,
//forms, attributes) and locate the workflow attributes.
if ( IsDefined( obj ) )
for r in array
if ( { r.TYPE, r.SUBTYPE } == { obj.fType, obj.fSubType } )
found = True
break
end
end
//When the attributes RecArray is found, store it in attribs.
//Then reset the found variable so that it can be used again.
if ( found )
attribs = r.USERDATA
found = False
//Walk through the attribute's RecArray looking for the
//UserName attribute.
for r in attribs
if ( r.Name == 'UserName' )
userName = r.Value
found = True
break
end
end
//When the UserName attribute is found, retrieve the UserID
//variable.
if ( found )
performer = UAPI.GetUser( uSession.fSession, userName )
//When the UserID variable is found, set its value.
if ( IsNotError( performer ) )
userID = performer[ 1 ].ID
else
userID = performer
end
end
end
end
//If the userID variable is not found, return an error. You can
//set the error to Error.Get( 600 ), which is a generic workflow
//error. If you want to display a more specific error message,
//you can set fErrorMsg in the WSession object.
if ( !IsDefined( userID ) )
userID = Error.Get( 600 )
wSession.fErrorMsg = "Could not find the attribute UserName" +\
"to determine user."
end
return( userID )
end