Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi Bracken,

Did you check the rowCount for that query?

If it is giving more than 1 then array should hold multiple values

Check what comes in log

(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();
    gs.info('Row Count is:' + m2moim.getRowCount());
    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

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

Perfect, thanks a lot Pradeep

You are very welcome @bracken91 

Hi @Pradeep Sharma 

This has slightly changed and I'm now running the business rule on the table where I was orginally doing a  gliderecord to. Using the same code, I changed a few things round but now isn't working. Can you help me understand where I'm going wrong please? The log finds the records so it's just a case of pushing them to the field.

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

    var entList = [];
    var m2moim = new GlideRecord('x_lbg_insider_risk_insider_access_lookup');
    m2moim.addQuery('sys_id', current.ir_access_categorisation);
    m2moim.query();

    while (m2moim.next()) {
		
        entList.push(current.catalog_access.toString());

    }

    m2moim.u_oim_entitlements = entList.join();

})(current, previous);