- 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-05-2017 10:34 AM
Hi Patrick,
Just wanted to check one thing, are you trying to copy the date from parent to child table every time? if yes, then as Shloke said Business rule is good enough. I was an impression that when you open a child record by clicking the related list New Button first time then you need should be copied there.
In your code below if I understand you need to pull data from parent to child table and you have created the Business Rule on child table. if yes in that case your current object is for Child table and gr is for parent table then you need to pass the value from gr object to Current object. Just updated the code below, Please check if it works.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('x_cur_oc_feedback_oc_feedback');//this is my parent table
gr.addQuery('<field name which hold child sys_id>',current.sys_id);// ocpg_sponsor is the field on my parent table I want to pull data from
gr.query();
if(gr.next())
{
//gr.description=current.ocpg_sponsor;// ocpg_sponsor is the field on my child table I want to autopopulate
gr.update();
current.ocpg_sponsor = gr.<field name which you want to pass to child table>; //if it's not a reference field
current.ocpg_sponsor = gr.getDisplayValue<field name which you want to pass to child table>; //if it's a reference field
current.update();
}
})(current, previous);
Hope this helps, please let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 10:39 AM
hi Shloke, thanks for the feedback,
so in your example, is "request_item" the field name for your child table Description field? You original said you were sending the value from your Quantity field to your Description field...so I guess I'm confused where your "request_item" field comes in?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 10:49 AM
Hi,
You need a Relationship between your Parent Table and Child Table say a field on the Child Item which is referencing to the parent Item. For me it is the Request Item(request_item) field which is a reference one creating a Relationship between the two tables i.e. sc_req_item and sc_task. So Please check for your two table which is a common reference field which defines the Relation between your two tables and copy that field in place of request_item. Rest of the code remains the same.
This will allow you to copy values from Parent table field to Child Table field.
Hope this clarifies your doubt.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 10:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 11:02 AM
Hi,
Got it. Simply replace "request_item" in the script above with "parent". That should work for you.
Regards,
Shloke
Regards,
Shloke