Send Notification based on a variable answer?

Gemma4
Mega Sage

Hi Everyone, 
I created a notification to send if a catalog item variable is Yes - see attached details. The good news is that the notification sends when the variable "Additional Information =Yes" However, the bad news is that the notification is constantly sending when any update is made since the variable is always yes. Any suggestions how I can trigger this notification to only send one time when Additional Information changes to Yes? I verified changes to is not an option to select after the variable is selected. 

thanks in advance for any feedback you have.

 

 

9 REPLIES 9

Hi @Hemanth M1 

Thanks so much for the feedback. I suspected I needed to do something similar to what you suggested but wasn't quite sure how. I think we are close to resolution. Unfortunately multiple emails are still being generated when the state is change, assigned to is added etc. I believe the script isn't working because additional information starts in a "no" state and should only trigger when it is changed to yes. Attached is a copy of the notification, event, br, variable. Please let me know if you have any suggestions. 

thanks

 

Hi @Gemma4 ,

Remove all the condition in the notification

when the RITM being submitted Additional information is "No" right

 

in the BR script, change this

if (previous.variables.additional_information== "no" || previous.variables.additional_information== "No") { //check previous value is no

        if (current.variables.additional_information == "Yes" || current.variables.additional_information == "yes") //check if the updated value is yes
            gs.eventQueue('eventname', current, gs.getUserName()); //replace gs.getUserName() with the user you want to send email

    }

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Hi @Hemanth M1 

Can I get some feedback and better understanding on the script? Why do I need to add the following? I don't have this in any of the other scripts or email notifications. I believe they use the out of the box email accounts- from information and would prefer to leave the out of the box from in place. What are your thoughts?

gs.getUserName()); //replace gs.getUserName() with the user you want to send email

    }

 

Hi @Gemma4 ,

 

gs.eventQueue : to call Notification through events more info :https://www.servicenow.com/community/developer-forum/gs-eventqueue/m-p/1529243 

 

the challenge here is , you want to trigger email during variable change not during  Field change (fields have changes in the filter condition)

 

i have tested this in my PDI with one of the variable , you want to make sure the variablename and gs.eventQueue logic is correct.

if (previous.variables.additional_information== "no" || previous.variables.additional_information== "No") { //check previous value is no

        if (current.variables.additional_information == "Yes" || current.variables.additional_information == "yes") //check if the updated value is yes
            gs.eventQueue('eventname', current, gs.getUserName()); //replace gs.getUserName() with the user you want to send email

    }

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Hi @Hemanth M1 

Sorry for the late reply. I appreciate the explanation, however I'm still confused. Can I get clarity on what this part of the script means? 

gs.getUserName()); //replace gs.getUserName() with the user you want to send email

I created the notification, event, and business rule. See attached. Everything seems to be running and generating emails correctly. However, I am seeking to understand your concerns and gain wisdom if this is an effective approach or if you see any issues. 

thanks so much for your feedback as this isn't my strength.

BRScript.pngBRActions.pngBRWhenToRun.pngeventNotification.pngwhatWillItContain.pngWhoWillReceive2.pngnotificationCondition.png