Notification not working

sunil maddheshi
Tera Guru

Hey Everyone,

 

I am trying to trigger a notification through background script using event, but email is not triggering, when i checked the event log i can see event has triggered but not sure why it is in ready state every time when i try to trigger. Please see the screenshot. ThankseventStuckinReadyState.png 

11 REPLIES 11

@Ankur Bawiskar 

User is active and have valid email id and notification preference is also enabled, I tried with other users as well but no luck, i run BG script multiple times all events are in ready state and not being processed. We also checked there are no long running job in background.

Runjay Patel
Giga Sage

Hi @sunil maddheshi ,

How are you getting ready state, have done customization on state field? Also check the recipient column, hope you are passing email ids.

If you are doing it in PDI then email wont trigger. to configure email account check this blog: https://servicenowwithrunjay.com/configuring-an-email-account-in-a-servicenow-pdi/ 

RunjayPatel_0-1735275677848.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

yuvarajkate
Giga Guru

Recheck your parameters and the recipients. 

Also if you are using it on your PDI, i doubt PDIs are allowed to send emails. Earlier you could but now i doubt it.

sunil maddheshi
Tera Guru

@Ankur Bawiskar @Runjay Patel @yuvarajkate 

It is customer instance not PDI, I am trying to trigger notification using background script(for testing purpose later will move to schedule job), and using that event in the notification with email body and i have added a recipient in notification which has valid email id. Below is my background script and screenshot of notification.

// send the notification if custom fields in the table has empty value in all the records
var tableName = ['sn_grc_issue', 'sn_grc_task', 'sn_audit_engagement'];
 for (var i = 0; i < tableName.length; i++) {
     var fieldArr = [];
     var dictionaryGR = new GlideRecord('sys_dictionary');
     dictionaryGR.addEncodedQuery('elementSTARTSWITHu_^active=true^name=' + tableName[i]);
     dictionaryGR.query();
     gs.info(dictionaryGR.getRowCount());
     while (dictionaryGR.next()) {
         checkUnusedField(tableName[i], dictionaryGR.element, dictionaryGR.column_label);
     }
     gs.info("Un-used fields on table " + tableName[i] + " are " + fieldArr); 
     if (fieldArr.length > 0) {
        gs.info("inside if");
         gs.eventQueue('unused_field_event', dictionaryGR, tableName[i], fieldArr);
     }
 }

 function checkUnusedField(table, field_name, field_label) {
     var tableGr = new GlideRecord(table);
     tableGr.addEncodedQuery('' + field_name + '!=NULL');
     tableGr.query();
     if (tableGr.getRowCount() == 0) {  //field has empty value in all records
         fieldArr.push(field_label + " ");
     }

 }

notification_sc.pngNotif_reciepient.pngNotif_body.png

 

Hi @sunil maddheshi ,

 

Your code is working fine, if recipients have valid email id then it should process the email.

Open the email log in new window and check the processing log.

RunjayPatel_0-1735303557550.png

 

If found any error or warning then share

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------