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

Hi @kamlesh kjmar thank you, that worked for me.

 

@AnubhavRitolia thank you, Sorry i did not do great job explaining.