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

Hi Vasu ch!
I would rather use this as an analysis tool and I don't think you can run bulk updates 😄
You can do a quick test to analyze what happens when you click "Save" in Flow designer.
Most likely ( but not 100% ) there will be an endpoint called with a payload containing the changes.
Will try when I get some spare time to look into this further 😄

Got it. Looking at the complexity around the flow designer tables, I think its better to go with manual updates. 

 

Thanks @Rada Florin-Adr .