Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Flow Designer - Search through flows efficiently with scripts

Rada Florin-Adr
Tera Contributor

Today we will explore a method I've recently developed while looking over the Network Requests generated while a flow is loaded in Flow Designer.

After a long research through the tables that "make" a flow , I've realised there is no way you can actually find any details of the way an action is configured(eg. an "Update Record" action type).

That made me think that , somehow , Flow Designer dynamically builds the flow when we load it.But how does that happen ?

My investigation started with investigating the HTML tree to see if I can find any relevant table name where any helpful information might be stored.Nothing found.

After, I went through most of the Network Requests generated while a flow is loaded.

Well , without anymore suspense , this was it! Finally found it .

Turns out Servicenow uses this internal endpoint "https://{YOUR-INSTANCE-NAME}.service-now.com/api/now/processflow/flow/{FLOW-SYS-ID}?sysparm_transaction_scope=global" to dynamically generate the mapping between Actions and Inputs.

The response after this Network Request is done is a JSON full of informations.

For my interest , the most relevant keys inside the JSON are :

1)actionInstances ---> keeps mapping for actions like : Create Record , Update Record , Look up record etc.

actionInstances structure for a basic 3 actions FlowactionInstances structure for a basic 3 actions Flow

Expanded object inside actionInstancesExpanded object inside actionInstances



Relevant data inside an element of actionInstances : actionType -> Update Record ; inputs -> see on what table Update is against and what values are updated

2)flowLogicInstances ---> keeps mapping for logic actions like : If , For Each ,Set Flow Variable etc.

Now , what can you do with this ?

A simple use case (yet saves loads and loads of time) : We need to find out , what flow adds Additional Comments on the incident table.

With this method ? Simple as it sounds!

1)Create a script that iterates through all the flows by querying sys_hub_flow (of course you can limit the flows that you want to search based on table).

2)For each flow make a call to the newly discovered endpoint(add basic auth also) :

 var request  = new sn_ws.RESTMessageV2();        
    request.setHttpMethod('get');
    request.setEndpoint('https://{YOUR-INSTANCE-NAME}.service-now.com/api/now/processflow/flow/{FLOW-SYS-ID}?sysparm_transaction_scope=global');        
    request.setBasicAuth('{ADMIN-USER-NAME}', '{USER-PASSWORD}');
    response = request.execute();        
    httpResponseStatus = response.getStatusCode();  
    var body = response.getBody();
//ans will have the body with all the relevant data.

    var ans = JSON.parse(body);
    
//I recommend you first gs.info(JSON.stringify(ans)); so you can see the structure and decide what to do after.

3)Manipulate the data as you wish and get the relevant information from it.

That's all I wanted to share 😄

Thanks for reading and I hope this will help someone and spare your time going through all flows and checking all Actions.

11 REPLIES 11

TomiC
Tera Contributor

I get the following error when I try to execute it:

Request not sent to uri= https://xxx.service-now.com.service-now.com/api/now/processflow/flow/3Dcbc62c99837fda548ed5c365eeaad396?sysparm_transaction_scope=global : java.net.UnknownHostException: digitdevblue.service-now.com.service-now.com: digitdevblue.service-now.com.service-now.com
Script execution error: Script Identifier: null.null.script, Error Description: Empty JSON string, Script ES Level: 0
Evaluator: com.glide.script.RhinoEcmaError: Empty JSON string script : Line(155) column(0)

Looks like you have a typo in the first part of the URL : 

 digitdevblue.service-now.com.service-now.com

 

Also , make sure the user you use for AUTH has admin privileges ( admin should cover any permissions)

Geraldina Valer
Tera Contributor

Hi rada! 

We need a script that, using an assignment group, returns all the flows where it is used. 

I tried using your script with an admin user, but it didn’t work.

 

 

 

*** Script: {"error":{"message":"User Not Authenticated","detail":"Required to provide Auth information"},"status":"failure"}