Active IQ Unified Manager Discussions

How to generate the User-Input XML or JSON Body for executing workflows via REST APIs: The Solution

sinhaa
9,178 Views

I see that executing a workflow via REST APIs requires lot of work to be done just to prepare the right User-input XML body. Any mistake and you have some major debugging to do.

 

  1. Larger the number of User-Inputs, the bigger is the problem.
  2. Life is so much easier at the WFA GUI with Display names and tooltip help for User Inputs which are very easy for reading and providing the right values. I don't have any such privileges when manually preparing the User-Input XML body.
  3. It’s been asked numerous times how to provide User-Input values for type table, or Query (Multi-Select) etc. These are complex User-Input types and has lots of scope for user mistakes.
  4. I can have User-input dependency at WFA GUI which allows me to make the right selection, but while preparing my XML body I need to take care of it myself.
  5. An operator is allowed to execute workflows, but the same Display names which help him make the right user-inputs, makes it impossible for him to prepare the user-input body xml. Display names can't be used in in XML body and he can't know the exact parameter names by looking at the Display names. So he need to always contact the Admins/Architects for this. And Architects/Admins can't be expected to keep providing User-Input XML body to operators every operator.

 

How about if I could enter all the User-Input values in my workflow execution at WFA GUI, I can do a preview which passed to my satisfaction and then I can magically get the XML body for it which I can use to execute my workflow from REST APIs from any client. It could be so very much easy for me than building my User-Input XML body manually.

 

This is exactly what I'm going to give you right now. You open the WFA in browser, Go to your workflow, Start execution, you input values from GUI reading carefully the display names, preview it to your satisfaction and then get the XML body.

 

Assume your workflow is called “Workflow to Print a given Message”. It’s a simple workflow with only 1 user-input Displayed as "Message to Print"

 

Prerequisites:

 

 

The following are the one-time prerequisites.

 

  1. You need PowerShell 3.0 on your WFA server.
  2. Import the attached Generate_Workflow_User_Input_Body_in_XML.dar in your WFA. It’s our magical command called "Generate Workflow User Input Body in XML"
  3. Add credentials of a WFA Admin/Architect in you WFA itself with Name/IP: localhost

Match: Exact

Type: Other

Name/IP: localhost

Username: <WFA Admin/Architect Username>

Password: <User Password>

 

Credentials_localhost.png

 

 

Steps:

 

Suppose you have a workflow called "Workflow to Print a given Message". You want to execute it from REST apis and need to prepare the user input XML body.

 

 

  1. Select this workflow and clone it. The workflow clone is the exact copy of your original workflow word by word, input-by-input. It will open in Edit mode with name "Workflow to Print a given Message - copy".
  2. Add the command "Generate Workflow User Input Body in XML" at the beginning of your workflow. This is a must. This command need to be the first command in your cloned workflow.
  3. This command requires no input. So for its Parameters just press okay and save the workflow.
  4. You are done.
  5. Now Execute the clone workflow. You'll see all the user-inputs available to you. Make your choices as you wish. Preview it to confirm that planning is passed and u have no errors.
  6. Execute it now.
  7. You'll see that the our magical command "Generate Workflow User Input Body in XML" has failed in our clone workflow execution. Don't worry, its fate was decided to be so. But it didn't fail before giving me what I really wanted. i.e. my XML body for my real workflow. It displayed it in the GUI as well as saved it in your WFA server @ C:\temp\<workflow_name_dd_MM_yyyy_hh_mm_ss_.xml
  8. It also deleted all the reservations of this particular failed job. So NO major residue left to be cleaned.
  9. No matter how many and type of User-Inputs you have in your workflow, this will solve it all.

To summarize:

 

Clone Your workflow and Add the command "Generate Workflow User Input Body in XML" as your first command.

 

 

XML1.png

 

 

Start Execution, provide your User-inputs and preview it. Be satisfied and Press Okay. 

 

XML2.png

 

Now Execute it.  After a few scconds this cloned workflow will fail with Error "All done. The Workflow will fail now."

 

 

XML3.png

 

 

 

See the command execution logs for this command. You'll see the User-Input XML body. It has also saved the XML file at C:\temp in your WFA server.

 

XML4.png

 

 

Have fun.

 

sinhaa

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
1 ACCEPTED SOLUTION

sinhaa
6,885 Views

Hello WFA community users,

 

Adding the solution for JSON User-Input body as well. The method to use it remains same.

 

You can download and import the .dar file in WFA4.1 or above. Also providing the command code in .TXT format.

 

sinhaa

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

View solution in original post

4 REPLIES 4

promoth
8,412 Views

I am getting the following error message when i execute my workflow with the command in it.

 

 

Exception calling "Save" with "1" argument(s): "Could not find a part of the path 'C:\temp\TFG27 DS NFS volume Resize  - copy__03_10_2016_10_08_36_.xml'."

 

 

c:\temp exists on my PC.

 

 

 

PS C:\temp> ls
PS C:\temp>

 

 

 

Any help is much appreciated.

 

Thanks.,

 

Promoth

sinhaa
8,373 Views

@promoth

 

Okay. First thing I want to tell that DO NOT expect this command to pass. Its made to fail. Yeah not with this error,  see here.

 

The command tries to save the XML file on the WFA server's C:\temp\ . Have you installed your WFA on your PC? Do you have permission to create files in this folder? If not check if C:\temp is on your WFA server or not.

 

I'll modify the code to perform this check before. Will update the Dar file. 

 

 

In this image, you should still be getting the Uer-Input XML body in command execution logs even though saving the file failed. You can copy-paste that line. 

 

 

Sinhaa

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

sinhaa
8,351 Views

@promoth

 

 

Take the new code here.

 

You can also delete the old command and Import the new pdated .dar file attached. I've replaced the old dar with the new one.

 

sinhaa

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

sinhaa
6,886 Views

Hello WFA community users,

 

Adding the solution for JSON User-Input body as well. The method to use it remains same.

 

You can download and import the .dar file in WFA4.1 or above. Also providing the command code in .TXT format.

 

sinhaa

 

 

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.
Public