Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How to pass array values in a reference field ?

Mr khan
Tera Expert

Client script :

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var arr;
var parentRec = g_form.getValue('u_service_business_app');
var ga = new GlideAjax('bappUtils');
ga.addParam('sysparm_name', 'getChildValues');
ga.addParam('sysparm_recparent', parentRec);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// arr = 'sys_idIN' + answer; //.split(",");


var splitAnswer = answer.split(',');
for (var i = 0; i < splitAnswer.length; i++) {
g_form.setValue('u_tech_serv_off_app_service', splitAnswer[i]); //g_form.getValue('description') + '\n' + splitAnswer[i]);
}

 

// g_form.setValue('u_tech_serv_off_app_service', arr);
}

}

 

Script Include :

var bappUtils = Class.create();
bappUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getChildValues: function() {
var array = [];
var uid = this.getParameter('sysparm_recparent');
var prj = new GlideRecord('cmdb_rel_ci');
prj.addEncodedQuery("parent.sys_class_name=cmdb_ci_business_app^child.sys_class_name=cmdb_ci_service_auto");
prj.addQuery('parent.sys_id', uid);
prj.query();
while (prj.next()) {

var list1 = prj.child.sys_id;

array.push(list1); JSON.stringify(variable);

}
return JSON.stringify(array); //'sys_idIN' + array; //.toString(); //return 'sys_idIN' + retArrayy;
},
type: 'bappUtils'
});

 

 

#Anyone help me out here

1 ACCEPTED SOLUTION

@Mr khan 

like this

getChildValues: function(u_service_business_app) {
				var array = [];
				var prj = new GlideRecord('cmdb_rel_ci');
				prj.addEncodedQuery("parent.sys_class_name=cmdb_ci_business_app^child.sys_class_name=cmdb_ci_service_auto");
				prj.addQuery('parent.sys_id', u_service_business_app);
				prj.query();
				while (prj.next()) {
					var list1 = prj.child.sys_id;
					array.push(list1.toString());
				}
				return 'sys_idIN' + array;
			},
Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron

@Mr khan 

you want to restrict or you want to auto-populate. both are different things

1) for restriction - you need to use advanced ref qualifier

2) for auto-population - you need to ensure if field can hold multiple values then it should be of type List and not reference as reference field holds only 1 value at a time

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

Question: Two fields are there 1.Business application 2.Application services.

Hi ankur, i don't want to auto populate just i need to list out in reference field related application services based on the Business application.

If in the reference qualifier how i need to pass the current value to script include..

Javascript new bapp().getchildvalues(current).

 

@Mr khan 

like this you can send variable value

Javascript new bapp().getchildvalues(current.u_service_business_app);

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

Hello ankur, thank for the reply , can u pls help out on below query.
How to call that current.u_service_offer_business_app value in script include :
var bappUtils = Class.create();
bappUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getChildValues: function(bapp) {

var qString = bapp.u_service_offer_business_app;

or

getChildValues: function(u_service_business_app) {
------------------------------------------------------------------------
getChildValues: function() {

var prj = new GlideRecord('cmdb_rel_ci');
prj.addEncodedQuery("parent.sys_class_name=cmdb_ci_business_app^child.sys_class_name=cmdb_ci_service_auto");
prj.addQuery('parent.sys_id', qstring);
prj.query();
while (prj.next()) {
var list1 = prj.child.sys_id;
array.push(list1.toString());
}
return 'sys_idIN' + array;
},