- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 09:18 AM
Hi all,
I need to send the work notes history in the below format to external system using flow designer. Also, while Inbound, I need to process the work notes history and store it in Incident table. For inbound I am using Transform Map. Kindly provide some suggestions. Thanks.
"workNotesHistory": [
{
"workNote": "XXX",
"date": "XXX",
"user": "XXX",
"order": "XXX"
},
{
"workNote": "XXX",
"date": "XXX",
"user": "XXX",
"order": "XXX"
}
]
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 10:54 AM - edited 02-20-2023 10:55 AM
Hi @Priyadharashin1,
Getting all the work_notes out, should be possible via the getJournalEntry function.
var grIncident = new GlideRecord('incident');
if (grIncident.get('407bfe6b97142110b4f672571153afc9')) {
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = grIncident.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
for (var i = 0; i < na.length; i++)
gs.info(na[i]);
}
Would deliver (in a background script):
*** Script: 20-02-2023 19:34:56 - System Administrator (Work notes) Work Note #3
*** Script: 20-02-2023 19:34:51 - System Administrator (Work notes) Work Note #2
*** Script: 20-02-2023 19:34:45 - System Administrator (Work notes) Work note #1
*** Script:
If you combine that and split it (lazy splitting, since it is an example, you might want to split it in a better way with a proper regex to prevent issues with different date/time formatting etc.), you get something like this:
var grIncident = new GlideRecord('incident');
if (grIncident.get('407bfe6b97142110b4f672571153afc9')) {
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = grIncident.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
var result = [];
for (var i = na.length; i >= 0 ; i--) {
var nb = na[i].split("\n");
if (nb && nb[0]) {
var yourDate = nb[0].substr(0, 10);
var yourTime = nb[0].substr(11, 8);
var yourDateTime = nb[0].substr(0, 19);
var yourUser = nb[0].substr(22).split('(')[0];
var yourWorknote = nb[1];
var worknote = {
"workNote": yourWorknote,
"date": yourDateTime,
"user": yourUser,
"order": i
}
result.push(worknote);
}
}
gs.info(JSON.stringify(result))
}
resulting in:
[{"workNote":"Work note #1","date":"20-02-2023 19:34:45","user":"System Administrator ","order":2},{"workNote":"Work Note #2","date":"20-02-2023 19:34:51","user":"System Administrator ","order":1},{"workNote":"Work Note #3","date":"20-02-2023 19:34:56","user":"System Administrator ","order":0}]
If the answer helped you in any way, please mark it helpful. If it your solution, please accept it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 10:54 AM - edited 02-20-2023 10:55 AM
Hi @Priyadharashin1,
Getting all the work_notes out, should be possible via the getJournalEntry function.
var grIncident = new GlideRecord('incident');
if (grIncident.get('407bfe6b97142110b4f672571153afc9')) {
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = grIncident.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
for (var i = 0; i < na.length; i++)
gs.info(na[i]);
}
Would deliver (in a background script):
*** Script: 20-02-2023 19:34:56 - System Administrator (Work notes) Work Note #3
*** Script: 20-02-2023 19:34:51 - System Administrator (Work notes) Work Note #2
*** Script: 20-02-2023 19:34:45 - System Administrator (Work notes) Work note #1
*** Script:
If you combine that and split it (lazy splitting, since it is an example, you might want to split it in a better way with a proper regex to prevent issues with different date/time formatting etc.), you get something like this:
var grIncident = new GlideRecord('incident');
if (grIncident.get('407bfe6b97142110b4f672571153afc9')) {
//gets all journal entries as a string where each entry is delimited by '\n\n'
var notes = grIncident.work_notes.getJournalEntry(-1);
//stores each entry into an array of strings
var na = notes.split("\n\n");
var result = [];
for (var i = na.length; i >= 0 ; i--) {
var nb = na[i].split("\n");
if (nb && nb[0]) {
var yourDate = nb[0].substr(0, 10);
var yourTime = nb[0].substr(11, 8);
var yourDateTime = nb[0].substr(0, 19);
var yourUser = nb[0].substr(22).split('(')[0];
var yourWorknote = nb[1];
var worknote = {
"workNote": yourWorknote,
"date": yourDateTime,
"user": yourUser,
"order": i
}
result.push(worknote);
}
}
gs.info(JSON.stringify(result))
}
resulting in:
[{"workNote":"Work note #1","date":"20-02-2023 19:34:45","user":"System Administrator ","order":2},{"workNote":"Work Note #2","date":"20-02-2023 19:34:51","user":"System Administrator ","order":1},{"workNote":"Work Note #3","date":"20-02-2023 19:34:56","user":"System Administrator ","order":0}]
If the answer helped you in any way, please mark it helpful. If it your solution, please accept it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2023 01:06 AM
Hi Hayo,
Thanks for the response. I did few modifications, but this script worked..Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2024 05:25 AM
This script helps for a single record help me to fetch the same for multiple records along with the incident number for each work notes with that specific incident number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2024 06:16 AM
You should already be preselecting your Incidents in the flow. Then execute the script from within a For Each. May need to create your own custom action.