Weekly notifications are triggering multiple times for each record

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have 2 notifications. 1st notification i want to trigger weekly for the records created last week. In the notification email body, i have added link of those records which are created last week. I have a scheduled job which is executing weekly but for each record its generating multiple emails. I only want to trigger it once for all records.

 

Here is my scheduled job code:

 

var lastWeek = new GlideDateTime();
lastWeek.addDaysUTC(-7); // 7 days ago

var abc = new GlideRecord('xyz'); 
abc.addEncodedQuery('sys_created_onONLast week@javascript:gs.beginningOfLastWeek()@javascript:gs.endOfLastWeek()', lastWeek); /
abc.query();

var records = [];

while (abc.next()) {
records.push(abc.sys_id + "");
// Fire the event for each record created last week
//gs.eventQueue('x_roho_ewm_infor_0.po.records', abc, abc.sys_id, gs.getUserID());
}
if (records.length > 0) {
// You can choose to serialize the records array or send it as a string
var recordsStr = records.join(','); // Join the sys_ids with commas, for example

// Fire the event with all the records as a parameter
gs.eventQueue('x_roho_ewm_infor_0.po.records', null, recordsStr, gs.getUserID());
}

 

Today i have created the array and made some changes. When i tried to give random time there and tested it, the email didnt triggered and when i clicked on execute now. It triggered one time but how can i make sure that it will trigger only once every week for all the records at a time not per record per email.

 

2nd notification i have when po id is empty in the new records inserted/updated. I want to trigger the notification to a group. But this notification is also getting triggered multiple times for each record. I only want to trigger it once when a new records are inserted/updated and doesnt have any po id. Users can click on the link i have added in email id for those records which doesnt have any po id. I dont have any scheduled job for this.

 

Need help here any suggestions.

 

Thanks

10 REPLIES 10

SebastianKunzke
Kilo Sage
Kilo Sage

Hey,
I would try to solve it differently.

Use Case 1: Send information about mutliple records

You can have a look into scheduled reports. You are able to attach a list of records to the email. Based on the filter the mail will be send once.

 

Use Case 2: Inform one time

I assume the mail is send a couple times, because the condition is true with every update of the record. I am unsure, if you able to change the condition. If not I would create a flow, that sends the notification to the user. Within the flow make sure you select the flow trigger: Once

In this case the flow is only executed one time per record.

 

I hope my answer helps.

Kind regards

Sebastian

Usecase 1: I dont want to send report for this. Is my scheduled job correct? Have you checked the code for that?

Usecase 2: Its not a catalog item. So, i cant use flow here. Its a custom table into which data is getting pulled via integration.

I am not an expert in scripting. Because of that I try to solve everything with the flow designer. So if you do not want to use a scheduled report I would solve both in flows.

Use Case 1: Trigger Scheduled

SebastianKunzke_3-1739462745474.png

 

Action 1: Look up records

- For each: Update flow variable

Action 2: Send email with flow variable

 

Usecase 2: Tigger on change/insert

SebastianKunzke_0-1739462543657.png

 

Action 2: Send notification

The scheduled job worked fine for me. Thanks.