- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2023 07:49 AM - edited 01-18-2023 04:32 AM
Hi ,
We have a requirement to send the below details in a notification :
The Assignment Group has been changed from << Old Assignment Group >> to << New Assignment Group >>
The State has changed from << Old State >> to << New State >>
How to show the previous values of assignmnt grps,states ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 06:33 AM
you can use eventQueue based approach to trigger email and send the current and previous group value in event parm2
I hope you are aware on how to create event on your table, how to link email notification with event, how to include email script in email body
You can find examples in docs.
Example
After update BR
var obj = {};
obj["old_group"] = previous.assignment_group.toString();
obj["new_group"] = current.assignment_group.toString();
obj["old_state"] = previous.state.getDisplayValue().toString();
obj["new_state"] = current.state.getDisplayValue().toString();
gs.eventQueue('event_name', current, 'recipient', JSON.stringify(obj));
Then you can use email script in email body
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var jsonObj = JSON.parse(event.parm2);
template.print("The Assignment Group has been changed from " + jsonObj.old_group + " to " + jsonObj.new_group);
template.print("The state has been changed from " + jsonObj.old_state + " to " + jsonObj.new_state);
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2023 06:33 AM
you can use eventQueue based approach to trigger email and send the current and previous group value in event parm2
I hope you are aware on how to create event on your table, how to link email notification with event, how to include email script in email body
You can find examples in docs.
Example
After update BR
var obj = {};
obj["old_group"] = previous.assignment_group.toString();
obj["new_group"] = current.assignment_group.toString();
obj["old_state"] = previous.state.getDisplayValue().toString();
obj["new_state"] = current.state.getDisplayValue().toString();
gs.eventQueue('event_name', current, 'recipient', JSON.stringify(obj));
Then you can use email script in email body
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var jsonObj = JSON.parse(event.parm2);
template.print("The Assignment Group has been changed from " + jsonObj.old_group + " to " + jsonObj.new_group);
template.print("The state has been changed from " + jsonObj.old_state + " to " + jsonObj.new_state);
})(current, template, email, email_action, event);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2023 11:23 PM
Need your assistance here!
Tried to get trigger notification with after business rule when state is changed, I am able to trigger.
--> Here when used mail script to show in email body is
BR:-
(function executeRule(current, previous /*null when async*/ ) {
gs.addInfoMessage("BR running");
var obj={};
obj["new_state"] = current.state.getDisplayValue().toString();
obj["new_state"] = previous.state.getDisplayValue().toString();
gs.addInfoMessage("Old State: "+obj["new_state"] +" "+ "and" +" "+ "New State: "+obj["new_state"]);
gs.eventQueue('x_sink.state.previous.current', current, 'recipient', JSON.stringify(obj));
})(current, previous);
Mail script:
var jsonObj = JSON.parse(event.parm2);
template.print("The status of the ticket has changed from " + jsonObj.old_state + " to " + jsonObj.new_state);
I not getting the new. You cane see in below image it looks.
here in image can only getting old value.
Here I want to get, The status of the ticket has changed from Old Value to New Value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2023 12:00 AM