- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 05:41 AM
Hi All,
I have a requirement where I need to send 1 notifications to vendor's primary contact when due date is less than equal to 90 days from today. I created scheduled job where first I am getting the vendors list, then unique vendors. After that I am checking the primary contact and inside using while loop. Then calling the event. But while loop is executing only once and not checking records for next vendor. I am badly stuck in it from last 1 week. Below is the code:
var ven = [];
var newVen = [];
var primary=[];
var pven = [];
var now = new GlideDateTime();
gs.info('Now '+now);
//glide record vendor risk assessment table to get the vendor list
var gr = new GlideRecord('sn_vdr_risk_asmt_assessment');
gr.addEncodedQuery('state=2^vendor.status=active^questionnaire_due_dateBETWEENjavascript:gs.beginningOfLast3Months()@javascript:gs.endOfToday()');
gr.query();
gs.log('Total Number --'+gr.getRowCount()); // getting row count
while(gr.next()){
ven.push(gr.getValue('vendor'));
au = new ArrayUtil();
//var newVen = [];
newVen = au.unique(ven); //getting unique vendors
}
gs.log('Vendor SM----'+ven);
gs.log('vendor SM length--'+ven.length);
gs.log('new ven SM length--'+newVen.length);
var count = newVen.length;
gs.log('count newVen '+count);
var i=0;
//glide record contact table to get primary contact email id to send the notification
var contact = new GlideRecord('vm_vdr_contact');
for(i=0;i<=count;i=i+1){
gs.log("inside for loop"); //getting correct number of time (667)
contact.addEncodedQuery('company='+newVen[i]+'^primary_contact=true');
contact.query();
while(contact.next()){
gs.log('inside while sm---new'); // it is giving log only for 1 vendor
primary.push(contact.getValue('email'));
}
gs.eventQueue("vendor.event",gr,newVen[i],primary[i]);
}
gs.log("pven sm---"+primary);
gs.log("pven length sm----"+primary.length);
Kindly help as I am stuck on this from more than a week.
Regards,
Shivani
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2022 09:59 PM
Hi,
This issue is fixed by replacing while loop inside for loop with if loop.
Regards,
Shivani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 05:52 AM
Hi,
Your eventQueue line is outside your while loop. You're closing the bracket } from that while loop so it's not going to loop through any GlideRecord results. You'd need to move it up a line and close the bracket after it.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 06:05 AM
Hi,
Tried this as well, but no luck. Problem is that it is going inside while loop only for 1 vendor and for remaining vendors it is not going inside while itself.
Regards,
Shivani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 06:20 AM
Hi Shivani,
Can you update the script as below, it seems you are calling the gr object which does not make any value.
var ven = [];
var newVen = [];
var primary=[];
var pven = [];
var now = new GlideDateTime();
gs.info('Now '+now);
//glide record vendor risk assessment table to get the vendor list
var gr = new GlideRecord('sn_vdr_risk_asmt_assessment');
gr.addEncodedQuery('state=2^vendor.status=active^questionnaire_due_dateBETWEENjavascript:gs.beginningOfLast3Months()@javascript:gs.endOfToday()');
gr.query();
gs.log('Total Number --'+gr.getRowCount()); // getting row count
while(gr.next()){
ven.push(gr.getValue('vendor'));
au = new ArrayUtil();
//var newVen = [];
newVen = au.unique(ven); //getting unique vendors
}
gs.log('Vendor SM----'+ven);
gs.log('vendor SM length--'+ven.length);
gs.log('new ven SM length--'+newVen.length);
var count = newVen.length;
gs.log('count newVen '+count);
var i=0;
//glide record contact table to get primary contact email id to send the notification
var contact = new GlideRecord('vm_vdr_contact');
for(i=0;i<=count;i=i+1){
gs.log("inside for loop"); //getting correct number of time (667)
contact.addEncodedQuery('company='+newVen[i]+'^primary_contact=true');
contact.query();
while(contact.next()){
gs.log('inside while sm---new'); // it is giving log only for 1 vendor
primary.push(contact.getValue('email'));
}
gs.eventQueue("vendor.event",newVen[i],primary[i],'');
}
gs.log("pven sm---"+primary);
gs.log("pven length sm----"+primary.length);
Let me know if you face any issues.
Regards,
Deepankar Mathur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2022 06:24 AM
Hi Deepankar,
No luck. It is triggering the event but not sending the notification at all. The problem what I am facing is for loop is running 667 times, which is correct, so logically while loop also run for these many vendors, but it is running only for 1 vendor.
Regards,
Shivani