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

@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

Hello Ankur, it's not showing any values in application service field i gave condition like this 
javascript&colon;'parent='+current.u_service_business_app;  
condition is finde or need to try any different appraoch

 

@Mr khan 

are you sure the table has field with correct name i.e. parent

also that field should refer to table being referred by u_service_business_app

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

No parent field is not and it's not referring that table, business application and application services are both different tables.

Reference qualifier condition: Javascript application services backend name i need to mentioned or i need to call the function itself here only orn Anything else?