Workflow run script to take List Collector values and populate Related List.

Wesley Breshear
Tera Expert

Hello,

Needing some help with a workflow run script.  I am trying to take reference values from a List Colletor variable (i.e., Business Services) on my catalog request item and associate those records to a related list of my Certificate record.  Basically, I want to associate all Business Services that is tied to Certificate record being viewed or Certificate record that is used by the following Business Services.

My script is adding records to my M2M related list table but my Business Service and Certificate Common Name columns are blank; so I am currently getting three blank records.

Assistance with what I might be missing?

//var cert = current.common_name.getValue('sys_id');  // Request Item reference variable of certificate record
//var list = current.variables.u_business_service_list;  // Request Item list collector of related business services

var cert = '9ad10b62dbd56f001bd3c170ba9619e1';  // Testing with certificate's sys_id
var list = [];
var list = 'App 1,App 2,App 3'; // Testing with strings 
var array = list.split(',');

for (var i=0; i < array.length; i++) {
        // M2M table, related list, certificate to business service
	var bs = new GlideRecord('x_teth_ekcm_m2m_business_ser_certificates');  
	bs.setLimit(10);
	bs.addQuery('business_service', '!=', array[i]);
	bs.addQuery('certificate_common_name', '!=', cert);
	bs.query();
	
	if(bs) {
		bs.initialize();
		bs.business_service = array[i];
		bs.certificate_common_name = cert;
		bs.update();
	}
}

Thank you,

-Wesley

1 ACCEPTED SOLUTION

Hi Wesley,

Can you do this; don't declare bsArray and use like this

var bsArray = current.variables.u_business_service_list.toString();

bsArray = bsArray.split(",");

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

13 REPLIES 13

Hi,

update the query as this so that it iterates all sys_ids using IN operator

var cldappl = current.variables.application_names.toString();//List Collector
var gr = new GlideRecord('u_table_name');
gr.addQuery('sys_id', 'IN' , cldappl);
gr.query();
while (gr.next()) {
    gr.u_business_owner = current.variables.please_update_the_business_owner;//field is getting updated in the table this is again a list collector.
    gr.update();
}

Regards
Ankur

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

@Ankur Bawiskar : I am unsure of what is going wrong, but I am still getting only one value. which is the first value of business owner member while the second value is still getting ignored. Can you please advise

I would suggest to open new thread as this is quite older one and answered

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

I have opened  new thread if you can check. 

Multiple Value Update in a table through a Catalog form using scripts