populating a field on a record with info from another table

patricklatella
Mega Sage

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;
 
},
});

1 ACCEPTED SOLUTION

patricklatella
Mega Sage

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!


View solution in original post

26 REPLIES 26

patricklatella
Mega Sage

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!


I think, we were also checking that at some point.



Perfect. It worked finally.