Remove next line from string

Kshitij Chakarv
Tera Contributor

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

 

 
 

 

1 ACCEPTED SOLUTION

Hi @Kshitij Chakarv 

 

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

View solution in original post

5 REPLIES 5

AnubhavRitolia
Mega Sage
Mega Sage

Hi @Kshitij Chakarv 

 

Can you elaborate more with couple of examples?

 

Your requirement and script looks quite different.

 

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

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

@Kshitij Chakarv 

 

Still confused. Can you please share example of input and output please. What can be value and what should be exact output from Script.

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

Hi @Kshitij Chakarv 

 

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