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

can you provide exact code you trying please; I will replicate the error and help you out?


Also if you can share what exactly the output should look like?


Hi Sushant,


I have written a BR on update on a table when additional comments changes, it should copy all the additional comments and send it to another field.


Same script works for worknotes but not additional comments.


I would like all the additional comments entered in new line. I need this so i can send it to 3rd party system and they have 1 field for it. So whenver any update i need to copy all the prev comments also and send. But i see an undefined infront.



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



}


gs.addInfoMessage(com);


Pleas help me in getting that removed.


I feel better way can be querying directly on the sys_journal_field table:



try replacing your code with following; this will print you every comment.


you can also add time stamp while printing and who added that timestamp ; this will give you more control to play around and one simple query will do your job


----------------


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



}


----------------------------------------



every entry can be added to your field as a appended value


This is going as new entry for everytym additional comment is added. I wanted all to show in a one infomessage separated by line breaks.