- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 06:17 AM
Hi All,
I want to remove everything after new line from custom field.
I am using This field transform script.
answer = (function transformEntry(source) {
var GR = source.u_description.toString();
var index = GR.indexOf("Fault Offset:");
var event = GR.indexOf("Event Details :");
if (index != -1) {
gs.log('Inside loop');
var offset = GR.substring(index, index + 22);
gs.log('fault =' + index);
return source.u_short_description.toString() + ' ' + offset;
} else {
gs.log('event details found');
gs.log('Event details =' + event);
var edetails = GR.substring(event, event + 50);
return source.u_short_description.toString() + ' ' + edetails;
}
})(source);
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 09:16 PM
Try the below script, I am considering you are receiving value in edetails field :
var edetails = GR.substring(event, event + 50);
edetails = edetails.split("\n") [0] ;
This will remove everything after new line. If you do not have new line it will reurn your text and if it has new line it will remove everything from first new line
I hope this help.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 06:24 AM
Can you elaborate more with couple of examples?
Your requirement and script looks quite different.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 09:47 AM
Hi Anubhav,
var edetails = GR.substring(event, event + 50);
returns -
Event Details : Process: OUTLOOK.EXE 16.0.14326.20852
Last Event occur
Not always event details is consist of 50 character and thus snips it snips some part of next line
I was looking a way script only return 'Event Details : ' till end of line not part of next line
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 08:06 PM
Still confused. Can you please share example of input and output please. What can be value and what should be exact output from Script.
Thanks
Anubhav Ritolia
ServiceNow Rising Star 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2022 09:16 PM
Try the below script, I am considering you are receiving value in edetails field :
var edetails = GR.substring(event, event + 50);
edetails = edetails.split("\n") [0] ;
This will remove everything after new line. If you do not have new line it will reurn your text and if it has new line it will remove everything from first new line
I hope this help.
Please mark this helpful if this helps and Accept the solution if this solves your issue.
Regards,
Kamlesh