- 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-03-2017 01:30 AM
Hi,
As suggested above, Please write a After Update Business Rule on your Parent Table to Update the values required on your child Task Table as per the script mentioned below:
For example, Requested Item is my parent Table and Catalog Task is my Child Table for the Script shared below and I am copying the Value of Quantity field from RITM to Description field on the Catalog Task Table as mentioned below:
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item',current.sys_id);
gr.query();
if(gr.next())
{
gr.description=current.quantity;
gr.update();
}
})(current, previous);
Hope this helps.Mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 07:57 AM
Thanks for the help everyone, seem to be a couple ideas here...just needing a little clarity.
Shloke, does your solution also require the client script from Shishir's solution?
I've created the "after" business rule on my parent table with your code: "ocpg_sponsor" is the field on both my parent and my child record. With it like this it is not working...is there more needed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 08:18 AM
to clarify what I've done so far. I've create a business rule on my child table with the following advanced script: Still not working...any suggestions?
(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('ocpg_sponsor',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, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 08:28 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2017 09:44 AM
Hi Patrick,
Please find the responses for your queries:
1) Nope, The Business Rule which I shared will work for your requirement. There is no need for any Client Script.
2) Can you confirm whether the Business Rule has been written on the child Table or on the Parent Table?
3) "request_item" is the field on the child Table(sc_task) which is referencing to the Parent Table(sc_req_item) as shown below:
So in your Script kindly Replace the Reference field on your child table which is referencing the parent Table and it should work for you.
Regards,
Shloke
Regards,
Shloke