- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 11:55 PM
Hi Team,
I am trying to trigger single emails notification based on condition. My record counts in the table are dynamic. However I know the way to count them.
Below is the scenario how I want the system to behave
Suppose if I have 15 records in the table and they all belong to same supplier and reporting/service month. and Once the status of few records changes to 'Ready for Validation' I want to send a single notification and once all 15 record status changes to 'Ready for Validation'. then I want to trigger another notification.
The problem with my below script is, it sends out email notification for all the records instead of single notification. Basically i want two notifications one when the record count is less than 15 and one when record count is equal to 15.
This is a after Business rule.
(function executeRule(current, previous /*null when async*/) {
(function(){
var gr = new GlideAggregate('x_isgi_isg_governa_pm_sl_s');
gr.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()');
gr.addAggregate('COUNT','sp_name');
gr.setGroup(false);
gr.query();
while(gr.next()){
var gr1 = gr.getAggregate('COUNT','sp_name');
gs.addInfoMessage(gr1 + 'GlideAgrregate Count');
var gr2 = new GlideRecord('x_isgi_isg_governa_pm_sl_s');
gr2.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()^s_wf=6^sys_updated_onRELATIVEGE@hour@ago@1');
gr2.query();
if(gr2.getRowCount() > 0 && gr2.getRowCount() < gr1){
gs.eventQueue("x_isgi_isg_governa.Par_Submit _ISG_ACN",current);
gs.addInfoMessage(gr2.getRowCount() + " getrow count");
}
else if (gr1 == gr2.getRowCount()){
gs.addInfoMessage('full');
gs.eventQueue("x_isgi_isg_governa.Full_Submit _ISG_ACN",current);
}
}
})();
})(current, previous);
Awaiting your quick response.
Regards,
Narmi
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2017 12:47 AM
Hello Narmi,
Well, you could still create a parent table and add a new relation between the both. This way you won't need to modify the original table. I doubt, that this will be a simpler solution, but a cleaner one for sure.
But let's focus on what you are trying to archieve. Essentially your issue lies within the way your solution is handled: A business rule triggers on every record. Therefore every single record will trigger a notification (or let's say a notification action). This behaiviour will persist for business rules, since they trigger per record, not per table.
You could solve the issue by setting the business rules up in a way that they trigger a notification action, not the notification itself. This action (e.g. an explicit call of a script) is then handled by a script, which does the calculation/aggregation on the scope of the table. This means, that the calculation of the notificaiton would be done outside the record scope.
The other option would be to mark a record as soon as the initial notification has been send. This way the scope can be kept on the record level.
Again, i think your current way is neither ideal nor future proof. I would suggest to either set up a parent child relatioinship or to calculate the criterias outside of the record scope.
Greetings
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2017 12:14 AM
Hi Narmi,
The problem lies not in the script but the place where you are calling it.
Since you have created a BR, it will run on each record ( after the update I am guessing ) which in turn sends either the first or second notification based on the row counts.
So anytime, a record is updated, it will send a notification for that record.
gs.eventQueue("x_isgi_isg_governa.Par_Submit _ISG_ACN",current);
So how it works is let's say a record is updated, row count comes to be 4, it sends a notification.
Tomorrow another record is updated and then row count becomes 5 and again a notification.
Solution :
You need to set a flag somewhere in the same table which would say that notification has been triggered once and please don't send it until count goes to 15.
if(flagalreadysent==true){
if(gr2.getRowCount() > 0 && gr2.getRowCount() < gr1){
gs.eventQueue("x_isgi_isg_governa.Par_Submit _ISG_ACN",current);
gs.addInfoMessage(gr2.getRowCount() + " getrow count");
}
}
else if (gr1 == gr2.getRowCount()){
gs.addInfoMessage('full');
gs.eventQueue("x_isgi_isg_governa.Full_Submit _ISG_ACN",current);
}
Please mark correct/helpful based on the impact of the response.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2017 12:45 AM
Hi Gaurav,
Not sure how setting a flag will fix this issues. I have my script that you can refer in the first email and please guide me on how I can set the flag.
Regards,
Narmi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2017 12:53 AM
Hi,
When you are sending the email first time, you can set the flag to true, when the row count becomes 1 ( so first email will go out),
and then you can keep checking the flag everytime record gets updated, so that it wont trigger the event2 notification untill the rowcount becomes 15.
Thanks
Gaurav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2017 01:24 AM
Hi Gaurav,
I tried to modify the script as below but it triggers single notification for all each records.
(function executeRule(current, previous /*null when async*/) {
(function(){
var gr = new GlideAggregate('x_isgi_isg_governa_pm_sl_s');
gr.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()');
gr.addAggregate('COUNT','sp_name');
gr.setGroup(false);
gr.query();
while(gr.next()){
var gr1 = gr.getAggregate('COUNT','sp_name');
var flag = false;
var gr2 = new GlideRecord('x_isgi_isg_governa_pm_sl_s');
gr2.addEncodedQuery('sp_name=Supplier^serv_monONLast month@javascript:gs.beginningOfLastMonth()@javascript:gs.endOfLastMonth()^s_wf=6^sys_updated_onRELATIVEGE@hour@ago@1');
gr2.query();
while(gr2.next())
{
if(gr2.getRowCount() > 0 && gr2.getRowCount() < gr1 ){
flag=true;
}
else {
flag=false;
}
}
if(flag==true){
gs.eventQueue("x_isgi_isg_governa.Par_Submit _ISG_ACN",current);
}
if (gr1 == gr2.getRowCount()){
gs.addInfoMessage('full');
gs.eventQueue("x_isgi_isg_governa.Full_Submit _ISG_ACN",current);
}
}
})();
})(current, previous);