Need help with removing an undefined

surya123
Mega Guru

Hi All

This is the script i am using. It gives a undefined at the beginning of the additional comments. Is there a way i can just remove the 1st word?

var comments= current.comments.getJournalEntry(-1);

var com=[];

var na = comments.split("\n\n");       //stores each entry into an array of strings

for (var i = 0; i < na.length; i++) {

com+= na[i] + "<br>";                

}

It shows all correct but start with a undefined at beggining. can i do something to chop off that undefined?

1 ACCEPTED SOLUTION

see below new script with more control:



var gr = new GlideRecord('sys_journal_field');


gr.addQuery('element','comments');


gr.addQuery('element_id',current.sys_id);


gr.query();


while(gr.next()){


gs.addInfoMessage('"'+gr.value+'" added by '+ gr.sys_created_by+' at '+gr.sys_created_on);


}



in while loo you can add your logic to create multi line variable and have it assigned to your new field in one go


View solution in original post

14 REPLIES 14

Hey ,


try below now:



var gr = new GlideRecord('sys_journal_field');


gr.addQuery('element','comments');


gr.addQuery('element_id',current.sys_id);


gr.query();


var test='';


while(gr.next()){


var new_comm='"'+gr.value+'" added by '+ gr.sys_created_by+' at '+gr.sys_created_on+'\n';


test=test+new_comm;




}


current.u_test_desc=test;


current.update();



replace "current.u_test_desc" with your field name where you want to store the comment.


in infomessage you will not be able to see its working as there are limitations with length and size of infomessage.


see below new script with more control:



var gr = new GlideRecord('sys_journal_field');


gr.addQuery('element','comments');


gr.addQuery('element_id',current.sys_id);


gr.query();


while(gr.next()){


gs.addInfoMessage('"'+gr.value+'" added by '+ gr.sys_created_by+' at '+gr.sys_created_on);


}



in while loo you can add your logic to create multi line variable and have it assigned to your new field in one go


This one helped. Thanks


Can we try something like this:



var comments = current.comments.getJournalEntry(-1).replace('\n', '<br/>').replace('undefined', '');


gs.addInfoMessage(comments);


Hi shishir,


I need t print the additional comments in newlines.


Can you please help me with that. Because if i split, it adds undefined.