- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2017 03:53 PM
Hello all,
even though I've gotten this to work before, still struggling when I setup a new auto populate situation. I've got a custom field on an extended task table (the parent in this scenario) with name "ocpg_sponsor"...which is entered manually. I then have another custom field, also called "ocpg_sponsor" on another (separate) extended task table (child table in this scenario).
I need the ocpg_sponsor field in the child table to auto populate with the info from the ocpg_sponsor field in the parent record. Anyone see my code error? thanks!
my client script is:
function onLoad(control, oldValue, newValue, isLoading) {
if (newValue == ''){
g_form.setValue('ocpg_sponsor','');//name of field on form you want to auto populate
}
var ga = new GlideAjax('u_feedback_task_Ajax');//name of script include
ga.addParam('sysparm_name', 'getOCPGsponsor');//name of function on script include
ga.addParam('sysparm_ocpg', g_form.getValue('ocpg_sponsor'));//name of field on form triggering call
ga.getXML(OCPGsponsorLookup); // Always try to use asynchronous (getXML) calls rather than synchronous (getXMLWait)
}
// Callback function to process the response returned from the server
function OCPGsponsorLookup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('ocpg_sponsor',answer);//name of field on form you want to auto populate
}
and my script include is;
var u_feedback_task_Ajax = Class.create();
u_feedback_task_Ajax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getOCPGsponsor: function(){
var retVal; // Return value
var ocpg = this.getParameter('sysparm_ocpg');
var OCPGsponsorRec = new GlideRecord('x_cur_oc_feedback_tasks');//table where desired variable lives
OCPGsponsorRec.addQuery('ocpg_sponsor',ocpg);
OCPGsponsorRec.query();
// Query user records
if(OCPGsponsorRec.next())
{
retVal = OCPGsponsorRec.ocpg_sponsor;//name of field with info you want to grab
}
return retVal;
},
});
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 12:26 PM
I actually got it from help from Pradeep.
used a BEFORE business rule on the child table with the following script
current.ocpg_sponsor = current.parent.ocpg_sponsor.getDisplayValue();
done! thanks so much everyone!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2017 04:14 PM
I think you are trying to do onChange but client script talls about onLoad and i don't think onLoad supports newValue parameter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2017 04:22 PM
Hi Shishir, thanks for the reply. Yes I need the field on the child record to populate with the info from the field on the parent record when the child record (which is in a related list under the parent table) is first opened. This is not possible?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2017 04:38 PM
you can achieve in this way, please have your DISPLAY Business Rule on child table and get the data captured in g_scratchpad
Kindly TRY with below code.
Script Include:
function executeRule(current, previous /*null when async*/) {
//This function will be automatically called when this rule is processed.
var gr = new GlideRecord('parent table');
var getParentId = gr.get(parent.sys_id);
if(getParentId != '')
{
g_scratchpad.ocpg_sponsor= gr.ocpg_sponsor;
}
})(current, g_scratchpad);
Also have the onLoad Client Script on your child table.
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.isNewRecord()){
if(g_form.getValue('child table field name') == '') {
g_form.setValue('<child table field name>', g_scratchpad.ocpg_sponsor);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2017 07:24 PM
Just an advice which will simplify your implementation.
Why don't you add a update business rule on your parent table which will update the child records field? This will be real time data copy without the need of client side ajax. The server side code for this would be much simpler and you will also end up avoiding an extra Ajax call.