
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 09:38 AM
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'
});
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 09:55 AM
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);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 09:55 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2020 10:21 AM
Thank you Abhinay. That was very informative.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 10:31 AM
Thank you Abhinay, this worked perfectly.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2019 11:10 AM
you bet!