- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 01:48 PM
Based on this post Solved: Flow Designer - adding "substring to remove last c... - ServiceNow Community
and others I have tried a number of approaches to a script in the Update Requested Item Record action of a fb flow to copy the last 7 characters (the numeric part) of the RITM number into a new field I created on the sc_req_item table called u_contractor_id.
I am new to scripting
I have tried multiple variations of the following:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 10:18 PM
Can you show your configuration?
Please compare it with this (working) example:
Note that the applied transformations are as follows:
1.) Substring (Start Index=4, Leave End Index empty)
2.) Convert String to Number (No arguments)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 02:17 PM
var a = fd_data.trigger.request_item.number.toString();
var cid = a.substr(a.length - 7);
gs.info(cid);
Note: You can perform this using a string transformation in the flow designer, no scripting needed.
Note2: If you only want "skip" the "RITM" and the leading zeroes, you can also accomplish this by using flow designer transforms: 1.) substring to remote the RITM 2.) cast to integer (this will automatically remove the leading zeroes) 3.) cast to string again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 06:45 PM
Thank you that was helpful. Using transform functions makes sense. Both the number field and my custom field are string fields, so it seems like just the substring function would be enough without converting to a number then back to a string? But when I use the string transform with start index 4 and end index null and test it I get an "is not a valid record." error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 10:18 PM
Can you show your configuration?
Please compare it with this (working) example:
Note that the applied transformations are as follows:
1.) Substring (Start Index=4, Leave End Index empty)
2.) Convert String to Number (No arguments)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 08:48 PM
HI @Suzanne Coffman ,
I trust you are doing great.
To copy the last 7 characters (numeric part) of the RITM number into a new field called "u_contractor_id" on the sc_req_item table, you can use the following script in the "Update Requested Item Record" action of your Flow Designer flow:
var ritmNumber = fd_data.trigger.request_item.number;
var contractorId = ritmNumber.substring(ritmNumber.length - 7);
current.u_contractor_id = contractorId;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi