- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 03:34 AM
Need to print the Work Notes Comments as a single string in the below JSON format
02/13/2024 04:32:09 - Dexter Hines \n(User Response)\nHi User,\ntest for incident comments.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:52 AM
Hello @SAS21,
To achieve the desired format, you can utilize getJournalEntry(1) for the work notes field.
Example output:
Based on your code, you'll need to utilize the object variable to retrieve the value. Please refer to the code snippet below:
var inc = new GlideRecord('incident');
if (inc.get('57af7aec73d423002728660c4cf6a71c')) {
var jsonObj = {
'createdOn': inc.sys_created_on.toString(),
'user': inc.caller_id.name.toString(),
'inc_comments': 'Testing in PDI'
};
gs.print(jsonObj.createdOn+' - '+jsonObj.user+'\n'+jsonObj.inc_comments);
// gs.print(inc.work_notes.getJournalEntry(1));
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:14 AM - edited 04-17-2024 04:15 AM
Hi @SAS21 ,
You can refer below code :
var jsonObj = {
'createdOn' : 'createdOn',
'user' : 'Test',
'inc_comments' : 'val',
};
var data = JSON.stringify(jsonObj);
gs.info(data);
var finalData = data.replaceAll('\r', ' ');
gs.print(finalData);
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:21 AM - edited 04-17-2024 04:21 AM
for (var key in jsonObj ){
if(jsonObj.hasOwnProperty(key){
gs.info(jsonObj[key])
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:52 AM
Hello @SAS21,
To achieve the desired format, you can utilize getJournalEntry(1) for the work notes field.
Example output:
Based on your code, you'll need to utilize the object variable to retrieve the value. Please refer to the code snippet below:
var inc = new GlideRecord('incident');
if (inc.get('57af7aec73d423002728660c4cf6a71c')) {
var jsonObj = {
'createdOn': inc.sys_created_on.toString(),
'user': inc.caller_id.name.toString(),
'inc_comments': 'Testing in PDI'
};
gs.print(jsonObj.createdOn+' - '+jsonObj.user+'\n'+jsonObj.inc_comments);
// gs.print(inc.work_notes.getJournalEntry(1));
}
If my response helps you to resolve the issue close the question by Accepting solution and hit thumb icon. From Correct answers others will get benefited in future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2024 04:52 AM
Hi @SAS21
can you try the below code.
var jsonObj = {
'createdOn' : '04/15/2024 02:28:33',
'user' : 'Dexter Hines',
'inc_comments' : '(User Response)\r\nHi User\r\n test incident comments.',
};
var modifiedData= jsonObj.createdOn +'-'+jsonObj.user +jsonObj.inc_comments;
gs.info(modifiedData);
Thanks
dgarad