How to convert Script from workflow to flow designer custom action script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 06:25 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-02-2024 09:54 AM
Hi @Divya57 ,
Create a custom action, take description as input and run your script logic
Ex:
Flow:
Action details:
Hope this helps!!
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2024 01:45 AM - edited ‎08-05-2024 01:51 AM
@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();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2024 03:01 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2024 04:28 AM
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.