- 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 07:46 AM
can you provide exact code you trying please; I will replicate the error and help you out?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 07:51 AM
Also if you can share what exactly the output should look like?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 07:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 08:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2017 08:14 AM
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.