The CreatorCon Call for Content is officially open! Get started here.

How to convert Script from workflow to flow designer custom action script

Divya57
Tera Expert

Hi All,

I got a requirement to convert workflow into flow designer. Am facing one challenge on converting run script from workflow to flow designer. Can someone please help me out.

I have below run script:
var getdesc = current.description.toString();

var rp = getdesc.replace(/[^\x00-\x7F]/g," ");

var sp = rp.split('\n');

var l;

var lines = 0;

var Text = 'New Task';

for(i=0; i < sp.length; i++){

if(sp[k].indexOf(Text) > -1){

lines = i;

}

}

l = a.split('New Task URL: ')[1].split('\n')[0].trim();

current.variables.u_task_name=l.replace(/  +/g, ' ');

 

l = a.split('New Company: ')[1].split('\n')[0].trim();

current.variables.u_company_name=l.replace(/  +/g, ' ');

 

l = a.split('New Address URL: ')[1].split('\n')[0].trim();

current.variables.u_address_name=l.replace(/  +/g, ' ');

The above script is working fine in workflow. I need to convert this script from workflow to Flow designer. I know using Flow designer custom script action we can do it. can someone help me out how to do that ?
Thanks

 

 

 

5 REPLIES 5

Hemanth M1
Giga Sage
Giga Sage

Hi @Divya57 ,

 

Create a custom action, take description as input and run your script logic

Ex: 

 

Flow:

 

HemanthM1_0-1722617576380.png

 

Action details: 

HemanthM1_1-1722617653322.png

 

Hope this helps!!

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

@Hemanth M1 - Already tried this. initially i got the error "Cannot read property "1" and "0" from undefined". Then later i removed the[1] and [0] from the script and tried. Then it said 'variables' cannot read. Then added few more inputs and modified script below. But still not working.

var getdesc = current.description.toString();

var rp = getdesc.replace(/[^\x00-\x7F]/g," ");

var sp = rp.split('\n');

var l;

var lines = 0;

var Text = 'New Task';

for(i=0; i < sp.length; i++){

if(sp[k].indexOf(Text) > -1){

lines = i;

}

}

l = a.split('New Task URL: ').split('\n').trim();

inputs.requested_item.variables[inputs.getVar1] = l.replace(/  +/g, ' ');

inputs.requested_item.update();

 

l = a.split('New Company: ').split('\n').trim();

inputs.requested_item.variables[inputs.getVar2] = l.replace(/  +/g, ' ');

inputs.requested_item.update();

Hi,

You must either add all the needed input into your custom action, or rework the script, to get the sources from elsewhere.

There is rarely a 1-1 conversion doable from a workflow script to a script in Flow designer. All the things in your workflow that points to current.XXX must be reworked as inputs into your custom action, or defined in the script itself.

 

For us to help you further, please explain what the script should do, or provide other needed context.

Hi @OlaN 
Below is the my use case.
When servicenow receives email with subject 'xxxxxxxxxxxxxx' a inbound email action get triggers. Then that email action body contain description get copied into new RITM description. Later this workflow script executes and divide the description into respective variables.