The CreatorCon Call for Content is officially open! Get started here.

How to push GlideRecord query to an array

Pratiksha Lang1
Kilo Sage

How to push GlideRecord query to an array in a Before Query BR

Please find the code below:

I want to push the GlideRecord query to an array. 

Note : I have written this code on  a Before Query BR

 

var answer = [];
var grRole = new GlideAggregate('x_amspi_smdrs_app_role_matrix');
grRole.groupBy('site');
grRole.query();
while (grRole.next()) {
var grInp = new GlideRecord('x_amspi_smdrs_app_input_ola');
grInp.addQuery('site', grRole.site);
grInp.addQuery('role', 'DM');
grInp.query();
while (grInp.next()) {
gs.info('check code');
}

}

11 REPLIES 11

@Ian Mildon I am getting error - ArrayUtil undefined, maybe missing global qualifier and this is not working.

Try this edited version

getRoleAndSite();

function getRoleAndSite() {
    var grRole = new GlideAggregate('x_amspi_smdrs_app_role_matrix');
    grRole.groupBy('site');
    grRole.query();
    var getSite = [];
    while (grRole.next()) {
        getSite.push(grRole.site.toString());
    }

    var arrayUtil = new ArrayUtil();
	var answer = arrayUtil.unique(getSite)

    var grInp = new GlideRecord('x_amspi_smdrs_app_input_ola');
    grInp.addQuery('site', 'IN', answer);
    grInp.addQuery('role', 'DM');
    grInp.query();
    while (grInp.next()) {
        gs.info('check code');
    }
}