- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 07:13 AM
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?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 08:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 08:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 08:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 08:25 AM
This one helped. Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 07:51 AM
Can we try something like this:
var comments = current.comments.getJournalEntry(-1).replace('\n', '<br/>').replace('undefined', '');
gs.addInfoMessage(comments);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2017 08:00 AM
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.