- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 03:38 PM
Hello,
I am trying to figure out how to remove a change calendar meeting when a change state is modified to canceled. I am running Helsinki and have confirmed that the out of box Notify Change Calendar Remove notification is working when assigned to or date is changed per the business rule (Change Events).
I have tried to add the condition to the Notify Change Calendar Remove notification but didn't send notification when change was canceled. I also tried to add the below code to the change events business rule and still can't get it to send remove notification based on change being set to a state of canceled.
Any ideas on how to accomplish this would be greatly appreciated.
// Remove old calendar from current assigned to, due to state change canceled
if (current.state.changes() && current.state== 4) {
gs.eventQueue("change.calendar.notify.remove", current, current.state, previous.state);
}
}
Thanks,
Nolan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 12:19 PM
I just tested in my personal dev instance, and cancelled a change. Here is the full code working:
if (current.operation() == 'insert') {
gs.eventQueue("change.inserted", current, gs.getUserID(), gs.getUserName());
}
if (current.operation() == 'update') {
gs.eventQueue("change.updated", current, gs.getUserID(), gs.getUserName());
}
if (!current.assigned_to.nil() && current.assigned_to.changes()) {
gs.eventQueue("change.assigned", current, current.assigned_to.getDisplayValue() , previous.assigned_to.getDisplayValue());
}
if (current.priority.changes() && current.priority == 1) {
gs.eventQueue("change.priority.1", current, current.priority, previous.priority);
}
if (current.risk.changes() && current.risk== 1) {
gs.eventQueue("change.risk.1", current, current.risk, previous.risk);
}
if (current.start_date.changes() || current.end_date.changes() || current.assigned_to.changes()) {
if (!current.start_date.nil() && !current.end_date.nil() && !current.assigned_to.nil()) {
gs.eventQueue("change.calendar.notify", current, current.assigned_to, previous.assigned_to);
}
// Remove from previous assigned to, due to assigned_to changing
if (!previous.assigned_to.nil()) {
if (!current.assigned_to.nil() && current.assigned_to.changes() &&
(!previous.start_date.nil() && !previous.end_date.nil())) {
gs.eventQueue("change.calendar.notify.remove", current, current.assigned_to, previous.assigned_to);
}
}
// Remove old calendar from current assigned to, due to date changing
else if (!current.assigned_to.nil()) {
if ((current.start_date.changes() && !previous.start_date.nil()) ||
(current.end_date.changes() && !previous.end_date.nil())) {
gs.eventQueue("change.calendar.notify.remove", current, current.assigned_to, current.assigned_to);
}
}
}
if(current.state.changesTo(4)){
gs.eventQueue("change.calendar.notify.remove", current, current.assigned_to);
}
You can see line 50-52 is what I added to the OOB script.
Event Fired:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 08:02 PM
Hi Nolan,
Did you notice if event is getting fired?
If yes, then you need to check on your notification if "send to event creator" is checked.
You may also need to check if "assigend_to" or person you are trying to has valid email id in the system , i mean email field should not be blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 10:24 AM
Hello Deepak,
Thanks for your response.
I don't see that the event is firing at all when I "cancel" a change request. I don't get a sent item in the service now mailbox and looking over the system logs no sign of it firing when change request is canceled.
I am using a service now dev instance out of the box and sending all emails to myself which works for calendar removal when assigned to or date and time are changed which is what is coded in the Change events business rule out of the box.
I have send to event creator checked.
Please advise if any other ideas.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 10:36 AM
Your condition: if (current.state.changes() && current.state== 4)
I would try to remove the "&& current.state ==4" and see if the event fires.
Also, try to use the method changesTo()
For example, if current.state.changesTo("cancelled") -- It might be the actually "integer" value.. I just remember this when I added this feature to our change requests.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-29-2017 11:57 AM
Hello Jeffrey,
Thanks for your response.
If I remove && current.state ==4 it still didn't fire when state was changed.
I then tried changesTo() and still no luck. Tried both of them below.
if (current.state.changesTo("Canceled")) and if (current.state.changesTo("4")) {
Do I need to make changes to both business rule and add conditions to the notifications or just the business rule?
Here is the 3 sections of the business rule which the top 2 are out of the box and working but the 3rd one doesn't fire even with all the suggestions. I must have a syntax error with the added script.
// Remove from previous assigned to, due to assigned_to changing - Working
if (!previous.assigned_to.nil()) {
if (!current.assigned_to.nil() && current.assigned_to.changes() &&
(!previous.start_date.nil() && !previous.end_date.nil())) {
gs.eventQueue("change.calendar.notify.remove", current, current.assigned_to, previous.assigned_to);
}
}
// Remove old calendar from current assigned to, due to date changing - Working
else if (!current.assigned_to.nil()) {
if ((current.start_date.changes() && !previous.start_date.nil()) ||
(current.end_date.changes() && !previous.end_date.nil())) {
gs.eventQueue("change.calendar.notify.remove", current, current.assigned_to, current.assigned_to);
}
}
// Remove old calendar from current assigned to, due to state change canceled - Not working
if (current.state.changesTo("Canceled)) {
gs.eventQueue("change.calendar.notify.remove", current, current.state, previous.state);
}