
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 05:14 AM
I want to send a notification with the old value and new value (from sys_history_line table) when the company name changes on core_company table.
Notification Subject should be like below.
Company name changed from 'Old Company Name' to 'New Company Name'.
How to get the old value on the notification subject/body?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2023 07:25 AM
@Community Alums
why to use sys_history_line table?
you can use eventQueue based approach and send the old and new value
1) create event on that table
2) use after update BR on core_company table Name Changes to trigger the event
3) use script to trigger event and include the old and new value in event parameter
4) then use email script to print the old and new value
5) include the email script in email body. I hope you are aware on how to do this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.eventQueue('event_name', current, gs.getUserID(), current.name + '||' + previous.name);
})(current, previous);
Email script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var val = event.parm2.toString();
var newValue = val.split('||')[0];
var oldValue = val.split('||')[1];
template.print('Company name changed from ' + oldValue + 'to ' + newValue);
})(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
07-11-2023 07:25 AM
@Community Alums
why to use sys_history_line table?
you can use eventQueue based approach and send the old and new value
1) create event on that table
2) use after update BR on core_company table Name Changes to trigger the event
3) use script to trigger event and include the old and new value in event parameter
4) then use email script to print the old and new value
5) include the email script in email body. I hope you are aware on how to do this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
gs.eventQueue('event_name', current, gs.getUserID(), current.name + '||' + previous.name);
})(current, previous);
Email script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var val = event.parm2.toString();
var newValue = val.split('||')[0];
var oldValue = val.split('||')[1];
template.print('Company name changed from ' + oldValue + 'to ' + newValue);
})(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
07-11-2023 08:18 PM
@Community Alums
Hope you are doing good.
Did my reply answer your question?
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
09-25-2024 07:05 PM
Hi Ankur,
Your approach is correct but getting values not labels. Can you please check below text which I am getting.
Previous Priority: Priority changed from 2to 1 ( Here I want ' 2 - High to 1 - Critical').
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2024 07:35 PM
Hi Ankur,
Great thanks for your approach, It's working for my query.
Mail script :- incident_priority_email_script