Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Initiating a new process via code

Not applicable
Hi all,



I've read examples in the documents for initiating a new process with API's.



The problem is that the process instance state is -1, has anyone an idea about how to make it work and be able to pass the process instance to the next role? (I've tried with workitems but...)



Thanks a lot for your help,



damoon
8 Replies
Not applicable
Hi Damoon,



Here are the steps I take in scripts that initiate a workflow, that has been successfull. I am offering this in the hope that you may have missed one step and can work it out from this, (probably the .complete method towards the end, would be my guess). Obviously this is not the only way to do things, but it has worked for me.



First I create all required objects:

a Connection

a StartTask

a StatelessWorkItemData

a BinaryData (only if including attachments)

a XMLData



Then I open the connection and set the connection property of the StartTask.



Then I use the CreateProcessInstance method to create a new process instance.



Then I load the XML data into the XMLDataObject



Then I set the connection property of the StatelessWorkItemData object and call the .Begin method



Then, if required, I load attachement files into the BinaryData object, and use the AddAttachement method to include them in the StatelessWorkItemData object.



Then, to actually submit the workitem and complete the task, I use the .Complete method of the StatelessWorkItemData object.



Then as a last item, I close connections and clear any objects.



I hope this helps.

Sanna
Not applicable
Hi Sanna,



Thanks for your help, but how to get the xml needed to feed the XMLDataObject?



thanks once more 😃



Damoon
Not applicable
The data doesn't have to be in XML, it can also be URL-encoded. Depends on what data you want in the WorkItem's data structure. The WorkItem data is the data which is presented/modified in the various forms during the workflow.



You create one of either a WWWFormData or an XMLData and then populate it with data. The information on how to use these is in the COM object references in the docs.



Regards,

Rob McDougall
Not applicable
Damoon,



As usual, Rob is right.



As you can use the API to initiate a workflow from just about anything (we, for example, initate one as a result of a scanning event to distribute incoming scanned invoices), so how you create the datafile depends on your situation.



In the simplest form, all you need is a simple xml file that populates the fields you need populated, if any - one of the fastest ways to create the 'base'XML file is to run the form you are using for this task in test mode (F5 in the designer), enter the default data into it, and save the file (right click anywhere on the form and select Save Data...).



Then you can use XMLDom in your initiation script or application to load the base xml file and modify data prior to submitting it, if you need to.



Hope this helps. As Rob mentioned, the documentation does explain each of the objects available.



Cheers,

Sanna
Not applicable
Many thx to all of you, perfect answers and explanations 😃
Not applicable
Hi all,<br />Still a little stuck on this problem. <br /><br />When calling :<br />StateLessWorkItemData.Begin(strProcRef, XMLData)<br /><br />i pass strProcRef that is the string returned by StartTaskAdobe.CreateProcessInstance(strProcName)<br /><br />and<br /><br />XMLData loaded from a local file that i got as Sanna said<br />body of this file is :<br /><?xml version="1.0" encoding="UTF-8" standalone="yes"?><br /><start><br /><FR_NAME>username</FR_NAME><br /><MSGSUBJECT>subject</MSGSUBJECT><br /><FOLLOWUP></FOLLOWUP><br /><JFWF_ACTION>start</JFWF_ACTION><br /><JFWF_CHOICE></JFWF_CHOICE><br /><JFWF_AGENT></JFWF_AGENT><br /><JFWF_DELEGATE></JFWF_DELEGATE><br /><JFWF_DEBUGACTOR>initiator_name</JFWF_DEBUGACTOR><br /><JFWF_STATUS>RECEIVED</JFWF_STATUS><br /><JFWF_TRANSPORT>HTTP</JFWF_TRANSPORT><br /><JFWF_VERSION>6.2</JFWF_VERSION><br /><JFWF_INSTRUCTION>auto_launch_issue</JFWF_INSTRUCTION><br /><JFWF_READONLY>0</JFWF_READONLY><br /></start><br /><br />Does anybody gets where the error is?<br /><br />Thx once more
Not applicable
Damoon,



Is there a specific error message?



One thing that I did not mention before, is that if your process has more than one starttasks, you do need to name the starttask you want to use in the Begin action. (If there is only one start task in a process, it will use that by default.)



The other thing that could cause a problem, is that your datafile names action called 'start' as the action to take on the .Complete event. Are you sure there is a 'start' action available on the task selected?



Hope this helps,

Sanna
Not applicable
It is totally ok, i've read the doc and noticed that the submit needed to have the handle of the begin 😃

sorry and thx once more