"User-Friendly" Flow Designer Action Script??

Matthew Dever
Tera Contributor

So here's the situation...

 

  • I am creating a Flow that will create a new catalog item request, populating data from a different task's Multi-Row Variable Set (MRVS) when that task is closed (trigger).
  • The input value that I am retrieving in the Flow Designer Script Action is the MRVS that contains two fields: server and ip address.
  • I am then taking that MRVS and looping through each row in that set to grab only the IP addresses.  If there is not an IP address associated with the server, it will indicate as such with a combination of static and dynamic text.
  • Then I want to take the array of IP address from the "For in" loop and output that to a "Output Variable" I created.
  • Then pass that array back to the Flow and apply that to a semi-static description field on the new catalog item it creates.

Ironically, when I run the same loop in a background script, I easily get the results that I want.

var ips = [];
var array = [
    {
    server: 'Server1',
    ip: ''
    },
    {
    server: 'Server2',
    ip: '321.22.16.2'
    },
    {
        server: 'Server3',
        ip: '211.66.2.4'
    }
]
    
    for(i = 0; i < array.length; i++){
        if(array[i].ip == ''){
            ips.push('No IP data for ' + array[i].server)
        } else  ips.push(array[i].ip);
    }
    gs.print(ips);
*** Script: No IP data for Server1,321.22.16.2,211.66.2.4

The disjoint between the "user-friendly" flow designer script action and the normal scripting practice on the platform is glaringly apparent: it is not as cut and dry as one might be led to believe.

 

I have traversed through a maze of possible solutions from online resources, including (but not limited to) a plethora of ServiceNow Community posts, ServiceNow Product Docs, and independent sites found by a Google search.  Nothing I found solves my customer's requirement.

 

Can someone assist in solving this cryptic enigma that should not be so difficult to achieve?

 

Thank you.

1 ACCEPTED SOLUTION

I suggested that you pass it in as a string not an array.  So you need to change the input type and then you also may need to use a script for that passed value when you call your action.

Also put in some log statements to see what is going it.

 

Lastly the token error indicates that there is something wrong with what was passed in to be pared.

 

View solution in original post

4 REPLIES 4

DrewW
Mega Sage
Mega Sage

It feels like you are making this more complicated than it needs to be.  Last I remember a MRVS is stored as a string in JSON format.  So in your Action pass the MRVS in as a string and then just do JSON.parse(inputs.server_details) and then just output that from the action by just doing

 

outputs.ips = JSON.parse(inputs.server_details);

 

You may even be able to just use a flow variable and set it using a script.

 

Hi Drew:

 

Thank you for your quick response.

I will try the suggestions you provided and if they work, I will mark your response as the accepted solution.

Results from your suggestion solution. 

Input object from FlowInput object from FlowInput variableInput variableOuput actionOuput actionOuput variableOuput variableScriptScriptTest results errorTest results error

I suggested that you pass it in as a string not an array.  So you need to change the input type and then you also may need to use a script for that passed value when you call your action.

Also put in some log statements to see what is going it.

 

Lastly the token error indicates that there is something wrong with what was passed in to be pared.