Push multiple values into glide list field?

sndev1099
Giga Expert

Hi, 

I need to push multiple values into a glide list field from records retrieved from gliderecord. Currently it's only pushing one value. Is there something simple I'm missing? I've logged it and the glide record is returning 5 records.

(function executeRule(current, previous /*null when async*/) {

	var m2moim = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
	m2moim.addQuery('ir_access_categorisation', current.sys_id);
	m2moim.query();
	
	while (m2moim.next()) {
		
		//gs.info("AB 28_07 " + m2moim.sys_id);
		
		var entList = [];
		entList.push(m2moim.catalog_access);
		current.u_oim_entitlements = entList.toString();
	} 

})(current, previous);

 

find_real_file.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Brack,

Below please find the updated working code.

(function executeRule(current, previous /*null when async*/) {
  var entList = [];
    var m2Gr = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
    m2Gr.addQuery('ir_access_categorisation', current.sys_id);
    m2Gr.query();
    while (m2Gr.next()) {
        
        entList.push(m2Gr.catalog_access.toString());
    }
current.u_oim_entitlements = entList.join(); 

})(current, previous);

- Pradeep Sharma

View solution in original post

10 REPLIES 10

Sebastian R_
Kilo Sage

you have to use the following:

entList.push(m2moim.getValue('catalog_access'));

m2moim.catalog_access is a GlideElement (complex object) and is stored by reference (it´s like storing the same object in every loop).

Thanks Sebastian. This still only pushes one sys_id into the list rather than multiple.

Ankur Bawiskar
Tera Patron
Tera Patron

@bracken91 

Few things You need to do this;

1) use toString() while pushing the value into the array

2) Also you should set the value once your while loop ends

(function executeRule(current, previous /*null when async*/) {

    var m2moim = new GlideRecord('x_lbg_insider_risk_m2m_catalog_acce_ir_access_ca');
    m2moim.addQuery('ir_access_categorisation', current.sys_id);
    m2moim.query();
    
    while (m2moim.next()) {
        
        //gs.info("AB 28_07 " + m2moim.sys_id);
        
        var entList = [];
        entList.push(m2moim.catalog_access.toString());
    }

        current.u_oim_entitlements = entList.toString(); // this line outside the while loop

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks Ankur. Unfortunately, still only getting one value in the list