- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 07:38 AM
Hi All,
I am creating a script to extract some specific value followed after a keyword.
answer = (function transformEntry(source) {
var GR = source.u_description.toString();
var index = GR.indexOf("Fault Offset:");
var offset = GR.substring(index, index + 9);
return "source.u_short_description + '' + offset";
})(source);
Intension is to get the value after 'fault offset:' from source description is set to a custom field.
I see no result using this script. Please advise on this.
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 07:51 AM
Which type of transform script are you writing?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 07:59 AM
Try changing
return "source.u_short_description + '' + offset";
to
return source.u_short_description + ' ' + offset;
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 06:11 PM
Also keep in mind that indexOf() method is case-sensitive. For a case-insensitive lookup, use search() method instead.
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 08:03 AM
Please find updated transform map script below:
(function runTransformScript(source, map, log, target ) {
var desc = source.u_description.toString();
var index = GR.indexOf("Fault Offset:");
if(index!=-1)
{
var offset = GR.substring(13+index);
target.u_custom_field = source.u_short_description + ' ' + offset;
}
else
{
target.u_custom_field = source.u_short_description.toString() + ' ' + source.u_description.toString();
}
target.update();
})(source, map, log, target);
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 08:17 AM
Please try below code:
var desc = source.u_description.toString();
var index = GR.indexOf("Fault Offset:");
if(index!=-1)
{
var offset = GR.substring(13+index);
return source.u_short_description + ' ' + offset;
} else
{
return source.u_short_description.toString() + ' ' + source.u_description.toString();
}
return '';
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 09:07 AM
Thanks Anubhav, will try this. Please stand by 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 11:11 PM
Did you got a change to try my solution?
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023