Suppose that you want that a user to upload a document in a Workitem outside the GXflow Client, to do so you can use a WebPanel and a code code similar to this:
Event 'Create Instance'
&WorkflowServer.Connect('<UserId>','<UserPassword>')
&WorkflowProcessDefinition = &WorkflowServer.GetProcessDefinitionByName('<ProcessDefinitionName>')
&WorkflowProcessInstance = &WorkflowProcessDefinition.CreateInstance()
&WorkflowProcessInstance.Start()
&WorkflowActivity = &WorkflowProcessDefinition.GetActivityByName('<ActivityName>')
&WorkflowWorkitem = &WorkflowProcessInstance.GetWorkitemByActivity(&WorkflowActivity)
&WorkflowWorkitem.Assign(&WorkflowServer.ConnectedUser)
&WorkflowWorkitem.ChangeState(WorkflowWorkitemState.OPEN_ACTIVE_INPROCESS)
&WorkflowDocumentDefinition = &WorkflowServer.GetDocumentRepository().GetDocumentDefinitionByName('<DocumentName>')
&WorkflowFileExtension = &WorkflowDocumentDefinition.FileExtension
&File.Source = &WorkflowServer.GetSettingById(1350).Value+"\"+&WorkflowName+"."+&WorkflowFileExtension
&File.FromBase64String(&Blob.ToBase64String())
&WorkflowDocumentInstance = &WorkflowDocumentDefinition.CreateInstanceFromFile(&WorkflowWorkitem, &WorkflowName, &file.GetAbsoluteName())
&WorkflowError = &WorkflowDocumentDefinition.Error
msg(&WorkflowError.Message)
commit
Endevent
Where the data types variables are as follows:
&WorkflowServer – WorkflowServer
&WorkflowProcessDefinition – WorkflowProcessDefinition
&WorkflowProcessInstance – WorkflowProcessInstance
&WorkflowActivity – WorkflowActivity
&WorkflowWorkitem – WorkflowWorkitem
&WorkflowDocumentDefinition – WorkflowDocumentDefinition
&WorkflowFileExtension – WorkflowFileExtension
&File – File
&Blob – Blob
&WorkflowError – WorkflowError
&WorkflowName – WorkflowName
To upload a document, the task must be in the "In Process" state, which is why we use the &WorkflowWorkitem.ChangeState line. Remember to have previously configured the document preferences in the GXflow Backend.