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

einvaldserigsta
Kilo Sage

Hi,



It seems like you're making a string, not an array. Hence, try setting:



var com = "";



instead and see if that does the trick.


Hi Einvald


Still I see the same issue.


undefined12-20-2017 09:36:53 AM - Surya Soni (Additional comments) Test


Hello soni


why does it say "commentss" here var na1 = commentss.split("\n\n"); Please correct and lets see if it makes any difference.



Please mark my response as correct and helpful if it helped solved your question.
-Thanks

I have edited that post. I was also trying for worknotes. So, i had two. I removed that now