How to write Script Action in Flow Designer

Rohan04
Tera Contributor

I got the script for to create multiple RITM from single request based on MRVS and for that they have written Run script in workflow. I have an requirement of to write the script in flow designer. I am attaching the script which is written in workflow.

Your help will we Appriciated!!!

 

 

 
//get  row count for each MRVS row
var rowCount = current.variables.offboarding_user_list.getRowCount(); //This includes the internal name of the multi row variable set which is "offboarding_user_list"
for (var i = 0; i < rowCount; i++) {
 
//Define variables that will be the same on each RITM.  Add more as required
var req = current.request;
var reqBy = current.variables.requested_by;
 
//Grab each row of variables that will be different on each RITM
var row = current.variables.offboarding_user_list.getRow(i);
var user = row.user;
var nam = row.full_name;
var num = row.employee_number;
var mgr = row.manager;
 
//Crete a RITM for each row
var rec = new GlideRecord ('sc_req_item');
rec.cat_item = 'f06761511b582010e8addd3bdc4bcbfe';//catalog item for offboarding line item  NOTE:  This is REQUIRED to kick off the individual workflow created by each MRVS line item
rec.request = req;
rec.request.requested_for = reqBy;
rec.approval = 'approved';
rec.state = 1;
rec.stage = 'request_approved';
rec.assignment_group = 'ea42046613059200a01f3ea32244b0a0'; //sys_id of the Human Resources group
rec.short_description = "Off-boarding for user "+nam;
rec.description = "Off-board this user: \n - Name: "+nam+"\n - Employee Number: "+num+"\n - Manager: "+mgr;
 
rec.insert();
}
6 REPLIES 6

HrishabhKumar
Kilo Sage

Hi @Rohan04 ,

A direct solution to this would be for you to create a custom action, in there create a scripted step and add this code in that step and then use this action in your flow.

 

These steps will help you create an action.

1) Create new Action, same as you create a new flow.

2) Click on the plus icon to add a step and select script by scrolling the option.

    action1.png

 

action2.png

 

3) After creating the scripted step, add you code in the coding area.

   action3.png

 

Thanks,

Hope this helps.

 

Thanks,

Hope this helps.

Thanks @HrishabhKumar for giving the step-by-step procedure for writing script action in flow designer. I have followed the same but, it is throwing the error while running the flow. can you please give me the idea where I get stucking...or else can you provide me the exact flow that will be helpful for me...

 

Rohan04_0-1718170999719.png

 

@Rohan04 Could you paste your script here. It will give us an idea on where exactly the issue lies.

Hii @Sandeep Rajput The following is the script which i have used in Action Script
 
//get  row count for each MRVS row
var rowCount = current.variables.offboarding_user_list.getRowCount(); //This includes the internal name of the multi row variable set which is "offboarding_user_list"
for (var i = 0; i < rowCount; i++) {
 
//Define variables that will be the same on each RITM.  Add more as required
var req = current.request;
var reqBy = current.variables.requested_by;
 
//Grab each row of variables that will be different on each RITM
var row = current.variables.offboarding_user_list.getRow(i);
var user = row.user;
var nam = row.full_name;
var num = row.employee_number;
var mgr = row.manager;
 
//Crete a RITM for each row
var rec = new GlideRecord ('sc_req_item');
rec.cat_item = 'f06761511b582010e8addd3bdc4bcbfe';//catalog item for offboarding line item  NOTE:  This is REQUIRED to kick off the individual workflow created by each MRVS line item
rec.request = req;
rec.request.requested_for = reqBy;
rec.approval = 'approved';
rec.state = 1;
rec.stage = 'request_approved';
rec.assignment_group = 'ea42046613059200a01f3ea32244b0a0'; //sys_id of the Human Resources group
rec.short_description = "Off-boarding for user "+nam;
rec.description = "Off-board this user: \n - Name: "+nam+"\n - Employee Number: "+num+"\n - Manager: "+mgr;
 
rec.insert();
}