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

Some possible reasons:
1)Check the user if it's Active and not Locked out.
2)Make sure you have the right password for that user.


Rada Florin-Adr
Tera Contributor

Hi Valer!
Glad to meet you !
Your requirement will require some good knowledge about the response structure. I recommend you analyze a couple of flows with OOTB actions and some custom ones.
Now , for the error . May I please see how you've built your code to call that endpoint?

I used a local admin user that I created, and I was able to retrieve a JSON.

Hello,

Can you please provide the solution.   We are retiring a group and want to know where it is used.

Thanks,

Chad 

BTW SN needs a tool that does this OOTB.

Vasu ch
Kilo Sage

Hi @Rada Florin-Adr ,

 

Thats great approach to filter the flows. It really fits my requirement too. However, in my case, I need to replace a specific URL in all the flows/subflows. With your solution I can get the records I should modify,Is there any way I can update them as well using the script?

 

Thanks