Email notification when Record producer submitted.

SujitK
Tera Contributor

Scenario is there is a record producer , i want to send a email notification when ever the record producer submitted only when on one particular choice for a question  but problem is the receivers email are based on the user input in RP , and some variable of RP i need to show in notification body and those variable are NOT MAPPED in the table. What can be done.

1 ACCEPTED SOLUTION

@SujitK 

why you want to use producer.variableName?

The approach I suggested is to use after insert BR and syntax to get variable value is this

current.variables.variableName

it's simple

-> create event on your table

-> create notification which triggers based on the above event

a) set event parm1 contains recipient - True

b) set your body, subject etc

-> create after insert BR which checks your variable value

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	if(current.variables.variableName == 'your choice value'){
		gs.eventQueue('eventName', current, current.variables.variableNameForRecipient); // give here the variable name from where recipient should be picked
	}

})(current, previous);

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

@SujitK 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I need to show some inputs answers(not mapped ) in the mail body , how can i acheive that.

KanteS
Giga Guru

Hi @SujitK 

According to my understanding, Here we have two options:

1 : Create fields in table  that required in notification and Map the required Record Producer variables to created fields on the target table and use those fields in the notification for conditions, recipients, and email content.

 

2:If mapping is not possible, trigger a custom event from the Record Producer script and pass the required variable values as event parameters. Configure the notification to fire on that event and use the event parameters for recipients and email body.

 

If this helps, please mark the response as Helpful.

HabeebAjibS
Tera Contributor

-> Create an Event: Go to Event Registry and create a new event rp.notification.triggered
-> Create a Business Rule: Set it to run After - Insert on the target table
      Script: Check the RP variable value using current.variables.variable_name.
      Trigger Event: If conditions match, fire the event using gs.eventQueue ('rp.notification.triggered', current, recipient_email, variable_data);
-> Create an Email Notification:
     When to send: Set to "Event is fired" and select your event.
     Who will receive: Check Event parm1 contains recipient.
     Message Body (Mail Script): Since variables are not mapped, use a Notification Email Script to print them

 

I believe this should work. Kindly acknowledge by giving a thumps 👍🏽

Hemanth M1
Giga Sage

Hi @SujitK ,

 

Why don't you use the record producer script to send this email(once successful record creation) , you can easily access record producer variable using Producer api and use gs.eventQueue() as @Ankur Bawiskar  mentioned.

 

 

 

Accept and hit Helpful if it helps.

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