when state change to in progress and on hold and on hold reason get added in worknotes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 12:32 AM
Hi Team,
when we change state in progress and on hold and on hold reason get added in work notes but when we checked in logs its showing undefiend .
but in logs its only printing what is under worknotes like ttt but in work notes it is also state change to hold reason is :Awaiting vendor. i am not getting whole work notes . if anyone know please let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 01:15 AM
Hi @sangitakumari ,
I have made few changes to code and tried in my pdi its working,
please do give it a try,
(function executeRule(current, previous /*null when async*/ ) {
var state = "";
var specialcomment = "";
// var work_notes = current.work_notes.toString();
if (current.state == '2') {
current.work_notes = "State changed to:" + current.getDisplayValue('state');
gs.log("work_notes change for state in progress" + current.work_notes);
} else if (current.state == '3') {
if (current.hold_reason == '5' || current.hold_reason == '4' || current.hold_reason == '1') {
current.work_notes = "State changed to:" + current.getDisplayValue('state') + "and reason is:" + current.getDisplayValue('hold_reason');
gs.log("work_notes chnage for state" + current.work_notes);
}
} else if (current.state == '6' || current.state == '7') {
specialcomment = "Resolution Code : " + current.close_code + '\n' + "Resolution Notes : " + current.close_notes;
state = "Resolved"; //Resolved or Closed
} else if (current.state == '8') {
state = "Rejected"; //Rejected
}
gs.info('State: ' + state);
var demistocomment ="worknotes: " + current.work_notes.getJournalEntry(1) + 'Comments: '+ current.comments.getJournalEntry(1) + specialcomment;
gs.log("Work_notes and comment and resolution code and resolution notes" + demistocomment);
})(current, previous);
Results:
and make sure Resolution notes and resolution code are filled and incident has some worknote and comments
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Swathi Sarang

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2024 01:40 AM
Hi @sangitakumari ,
There are few issues in your script.
1. the way you are trying to access the worknotes is not right, as you should use journal entry for the same.
2. handling the state changes is also not correct.
please find the below script to solve your issue-
(function executeRule(current, previous /*null when async*/ ) {
var state = "";
var specialcomment = "";
// Checking and adding state change to work notes
if (current.state.toString() == '2') {
current.work_notes = "State changed to: " + current.getDisplayValue('state');
gs.log("work_notes change for state in progress: " + current.work_notes);
} else if (current.state.toString() == '3') {
if (current.hold_reason == '5' || current.hold_reason == '4' || current.hold_reason == '1') {
current.work_notes = "State changed to: " + current.getDisplayValue('state') + " and reason is: " + current.getDisplayValue('hold_reason');
gs.log("work_notes change for state on hold: " + current.work_notes);
}
} else if (current.state.toString() == '6' || current.state.toString() == '7') {
specialcomment = "Resolution Code: " + current.close_code + '\n' + "Resolution Notes: " + current.close_notes;
state = "Resolved"; // Resolved or Closed
} else if (current.state.toString() == '8') {
state = "Rejected"; // Rejected
}
// Combining work notes, comments, and special comments
var demistocomment = "worknotes: " + current.work_notes.getJournalEntry(1) + ' Comments: ' + current.comments.getJournalEntry(1) + specialcomment;
gs.log("Work_notes and comment and resolution code and resolution notes: " + demistocomment);
})(current, previous);
Note- Even Swathi's solution looks correct , please try both the solutions.
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar