This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - AML syntax for methods called from AML Studio or Innovator Admin tool

martin.dvoracek - Monday, September 26, 2016 8:19 AM:

  • We needed to call methods like StartWorkflow from AML Studio or Innovator Admin tool but we cannot figgure out the right syntax. Following AML returns an error:
    • <AML>
      <Item action='startWorkflow' type="Workflow Process" id="305F5FC94C3D4C1DBE6BB7298D1149F7" ></Item>
      </AML>
    • Error: Source item for Workflow Process not found
  • Is there any general guidance how to use methods from AML?

Thank you in advance



kentonv - Monday, October 3, 2016 11:44 AM:

Martin,

The syntax you are using should work to apply the method 'startWorkflow' using the <Item> as a context item. 

The error you are receiving seems to indicate that the workflow object cannot be found that should link your workflow process to your controlled item.

It isn't clear from your example how you obtained a Workflow Process id, but typically to start a workflow on your own, you would need to perform the following steps.

  1. Execute the instantiateWorkflow using the context item as the item you wish to use as the controlled item for the workflow (i.e.: an ECO). You need to include a property to indicate the 'WorkflowMap' that you wish to use as the template.
  2. Create a 'Workflow' item by using the following AML: <Item type='Workflow' action='add'><source_id>YOUR CONTROLLED ID</source_id><source_type>YOUR CONTROLLED TYPE ID</source_type><related_id>YOUR PROCESS ID</related_id></Item> The process ID would be returned from the instantiateWorkflow call.
  3. Execute the startWorkflow method using the workflow process as the context item (returned from step one execution).

If I had to guess, I would expect that step 2 is missing in your execution.

The following code should work, in a server method, as long as the context item includes a valid 'WorkflowMap' property.

' Instantiate workflow
Dim proc As Item = Me.apply("instantiateWorkflow")
If proc.isError Then Return proc
 
' Attach to item
Dim itemTypeId As String = Me.getAttribute("typeId")
If String.IsNullOrEmpty(itemTypeId) Then
  itemTypeId = inn.getItemByKeyedName("ItemType", Me.getType).getID
End If
Dim wf = inn.newItem("Workflow""add")
wf.setProperty("source_id"Me.getID())
wf.setProperty("source_type", itemTypeId)
wf.setProperty("related_id", proc.getID)
wf = wf.apply()
If wf.isError Then Return wf ' Activate workflow Return proc.apply("startWorkflow")