Email script are not working for some sent notification resulting it send blank info

komal44
Tera Contributor
var grContact = new GlideRecord('xyz');
    grContact.get(event.parm1);
    var scheduleValue = grContact.u_contact_by.u_advisor_schedule;
template.print(scheduleValue);

this is  script this works all the time 
but sometime do not print data in notification

I have checked even parameter it was  passed correctly 
I cannot find any result why it didn't print any data
4 REPLIES 4

Dominik Simunek
Tera Guru

Try to debug the script execution by adding more logging to see what is empty. It might be that no such record based on event parm is found, or that such a record has "u_contact_by" empty, or that record has "u_advisor_schedule" empty. I have drafted something for you, without testing it, so please review the code first. Test the code in non-prod environment, and it might help to find what is empty.

 

var grContact = new GlideRecord('xyz');
if (grContact.get(event.parm1)) {
    if (gs.nil(grContact.u_contact_by)) {
        template.print("Contact by is empty");
    } else if (gs.nil(grContact.u_contact_by.u_advisor_schedule)) {
        template.print("Advisor schedule is empty");
    } else {
        var scheduleValue = grContact.u_contact_by.u_advisor_schedule;
        template.print("Schedule value: " + scheduleValue);
    }
} else {
    template.print("No contact found for " + event.parm1);
}

 

Hi Dominik,
Thank you for your reply.
This issue is only occurring in the production environment; everything is working as expected in non-production. Therefore, attempting to log in for troubleshooting purposes has not been effective.
As I am new to ServiceNow, I am not entirely sure about the root cause. Is it possible that the notification is being processed before the record is saved? The notification is triggered by an "on before", "insert" business rule, and the mail script uses the current data from the same record.
Thank you for your guidance.

Hi Dominik,
Thank you for your reply.
This issue is only occurring in the production environment; everything is working as expected in non-production. Therefore, attempting to log in for troubleshooting purposes has not been effective.
As I am new to ServiceNow, I am not entirely sure about the root cause. Is it possible that the notification is being processed before the record is saved? The notification is triggered by an "on before insert" business rule, and the mail script uses the current data from the same record.
Thank you for your guidance.

SumanthDosapati
Mega Sage
Mega Sage

@komal44 

Did you add any logs? Where was it broke?