Transform map script

Kshitij Chakarv
Tera Contributor

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.

2 ACCEPTED SOLUTIONS

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Kshitij Chakarv 

 

Which type of transform script are you writing?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

View solution in original post

Slava Savitsky
Giga Sage

Try changing

return "source.u_short_description + '' + offset";

to

return source.u_short_description + ' ' + offset;

View solution in original post

9 REPLIES 9

Also keep in mind that indexOf() method is case-sensitive. For a case-insensitive lookup, use search() method instead.

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Kshitij Chakarv 

 

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);

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Kshitij Chakarv 

 

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 '';

 

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023

Thanks Anubhav, will try this. Please stand by 🙂

@Kshitij Chakarv  

 

Did you got a change to try my solution?

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023