Trigger event from record producer script

JJG
Kilo Guru

Hello,

I have a record producer that allows employees to send a follow-up email to a candidate. In this example, the employee chooses to send a custom email. When submitted, the record producer updates an existing record and triggers the event that sends the notification. I am trying to trigger the event to send this notification from the record producer script (Not client script). So far my code is not working, what am I missing?

Record Producer Script:

var prospectEmail = producer.email_address;
var prospectFirst = producer.first_name;
var grProspect = new GlideRecord("x_utsll_candidate_candidate_outreach");
grProspect.addQuery('email_address', prospectEmail);
grProspect.addQuery('first_name', prospectFirst);
grProspect.query();
if (grProspect.next()) {
grProspect.follow_up_email_log = producer.log_entry;
}

var temp = producer.custom_or_auto;
var eventParm1 = producer.email_address;
var email = producer.html_email;

if (temp == 'custom_email') {

gs.eventQueue("x_utsll_candidate.canOutCustom2", current, eventParm1); // Do i need to change 'current' to 'producer'?

grProspect.status = 'follow_up';

grProspect.update();

}

1 ACCEPTED SOLUTION

Just did a quick test with event in record producer script like below. Event got triggered, Parm1 has the mail address which could be used for the notification.

gs.eventQueue('test_event', '', '', 'test@example.com');

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi JJG,

Never tried this, so theoretical answer...
current does excist in the Record Producer Script. It's the just created record. So could work.

Question though. Why using an event (+ event registry), to trigger the notification? Could this already be achieved with a regular notification that runs on insert? Or is that due to the variables?

var temp = producer.custom_or_auto;
var eventParm1 = producer.email_address;
var email = producer.html_email;

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hey Mark,

The record producer does not insert a new record, it updates an existing record and then aborts submit.

Ah clear. Though if it aborts the submit/insert, then I would expect that current wouldn't work.  Because the record did not create. Not sure though 🙂

You could debug current or if the producer.custom_or_auto etc actually contain (the expected) values.

What is the reason for passing current to the event? Do you want to do anything with this? You could for example also drop this, and just pass the users or email addresses with the event.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Just did a quick test with event in record producer script like below. Event got triggered, Parm1 has the mail address which could be used for the notification.

gs.eventQueue('test_event', '', '', 'test@example.com');

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn