2 Replies Latest reply on Jul 1, 2019 7:07 PM by barjinders

    Call A workflow In Scriptable Task

    sean_gadson Novice

      Hello,

      is there a way to call a workflow in a scriptable task like you can with actions? 

        • 1. Re: Call A workflow In Scriptable Task
          qc4vmware Master

          Yes, but you have to retrieve the workflow object somehow.  There are plenty of ways to do that from statically defining it or looking it up by name or uuid etc.   It has a .execute() method.  You'll need to pass it in a properties type set correctly for each input needed to run the workflow.

          • 2. Re: Call A workflow In Scriptable Task
            barjinders Novice
            VMware Employees

            The whole process can be summarised as below:

             

            1) Get the workflow ID  for the workflow you want to run. You can get it either in code or copy it from GUI ->General Tab-> ID.

            2)Use an inbuilt library action to get the WF Object.

                var wfObject = System.getModule("com.vmware.library.workflow").getWorkflowById("<WF ID>");

            3) Input Parameters are passed as properties:

                var workflowParameters = new Properties();

                 workflowParameters.put("<InputParameter Name>", <value>);

             

            4) Execute the workflow with properties as input parameters. 

            var token = wfObject.execute(workflowParameters);

             

            5) Wait for the workflow to complete. You can use an inbuilt library action for that.

                        System.getModule("com.vmware.library.workflow").waitAllWorkflowComplete([token]);

                       

            6) Log if you want:

            System.debug("Workflow: " + token.name + "State: " + token.state);

            1 person found this helpful