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 set multiple field values using a script include / client script

Edwin Fuller
Tera Guru

Hello Developers, within my client script below I need to set two values for two fields. The "u_owner" field and the "u_planned_hours". Currently I'm only setting one field, the "u_owner" field. Can someone show me how to set both the "u_owner" field and the "u_planned_hours" field from the same script?

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;

}

var parentRec = g_form.getValue('parent');

var ga = new GlideAjax('TestingUtil');
ga.addParam('sysparm_name', 'getParentValues');
ga.addParam('sysparm_recparent', parentRec);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_owner', answer);
//g_form.setValue('u_planned_hours', answer);
}

}

 

Script Include:

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

getParentValues: function(){

var uid = this.getParameter('sysparm_recparent');
var prj = new GlideRecord('pm_project');
prj.addQuery('sys_id',uid);
prj.query();
if (prj.next()) {

return prj.project_manager;
//return prj.u_demand.u_rescreen_labor_hours;

}
},
type: 'TestingUtil'
});

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Pass the values in to json object and parse them on client side.

 

Script include:

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

getParentValues: function(){
var jsonObj={};
var uid = this.getParameter('sysparm_recparent');
var prj = new GlideRecord('pm_project');
prj.addQuery('sys_id',uid);
prj.query();
if (prj.next()) {

jsonObj.owner=String(prj.project_manager);
jsonObj.hours=String(prj.u_demand.u_rescreen_labor_hours);

}
return JSON.stringify(jsonObj);
},
type: 'TestingUtil'
});

 

 

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;

}

var parentRec = g_form.getValue('parent');

var ga = new GlideAjax('TestingUtil');
ga.addParam('sysparm_name', 'getParentValues');
ga.addParam('sysparm_recparent', parentRec);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var jsonObj=JSON.parse(answer);
g_form.setValue('u_owner', jsonObj.owner);
g_form.setValue('u_planned_hours', jsonObj.hours);
}

}

View solution in original post

4 REPLIES 4

Abhinay Erra
Giga Sage

Pass the values in to json object and parse them on client side.

 

Script include:

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

getParentValues: function(){
var jsonObj={};
var uid = this.getParameter('sysparm_recparent');
var prj = new GlideRecord('pm_project');
prj.addQuery('sys_id',uid);
prj.query();
if (prj.next()) {

jsonObj.owner=String(prj.project_manager);
jsonObj.hours=String(prj.u_demand.u_rescreen_labor_hours);

}
return JSON.stringify(jsonObj);
},
type: 'TestingUtil'
});

 

 

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;

}

var parentRec = g_form.getValue('parent');

var ga = new GlideAjax('TestingUtil');
ga.addParam('sysparm_name', 'getParentValues');
ga.addParam('sysparm_recparent', parentRec);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var jsonObj=JSON.parse(answer);
g_form.setValue('u_owner', jsonObj.owner);
g_form.setValue('u_planned_hours', jsonObj.hours);
}

}

Thank you Abhinay. That was very informative.

Edwin Fuller
Tera Guru

Thank you Abhinay, this worked perfectly.

you bet!