Loop through a set of records

Nazhath Mariam
Mega Expert

Hello

 

I am looking to build a section of my script with below requirement

 

I have a record number 123 from change request table and I need to check with N number of records from the approval table, matching this 123 number and check if a approval with a particular role (I have a customized fields called u_role) was triggered or not, in my case I am checked for "Architect" role.

 

I have written the below query, I know its not working because it is comparing with the whole dump. I am guessing I need a for loop here, any help with the code would be good.

 

var App = new GlideRecord('sysapproval_approver');
App.addQuery('sysapproval',taskCI.task.sys_id.toString()); // Comparing CR mumbers from affected CI table with CR numbers in approval table
App.query();
while(App.next())
{
if(App.u_role!="Enterprise")
CRnum.push(App.sysapproval.number.toString());

}

1 REPLY 1

SwarnadeepNandy
Mega Sage

Hello @Nazhath Mariam,

 

In your case, you want to check if an approval with a particular role was triggered or not and push the change request number to an array if not. You can use the following script to achieve this:

//Create an array to store the change request numbers 
var CRnum = [];

//Create a GlideRecord object for the sysapproval_approver table 
var App = new GlideRecord(‘sysapproval_approver’);

//Add a query condition to filter by change request number 
App.addQuery(‘sysapproval’,taskCI.task.sys_id.toString());

//Execute the query 
App.query();

//Iterate over the records using a while loop 
while (App.next()) {

//Get the role value of the current record 
var role = App.getValue(‘u_role’);

//Check if the role is not Enterprise 
if (role != “Enterprise”) {

//Push the change request number to the array
CRnum.push(App.getValue('sysapproval.number'));
} }

 

Hope this helps.

 

Kind Regards,

Swarnadeep Nandy