get value from parent table to child table

Akash68
Kilo Contributor

Hi,

in project table i have a field called "it segment".if that i"t segment" is equal to "xyz" then only i need to set some  values in child table(decision) like short description to "test"and approval required to yes

Please find the scripts used:

client script:table:Decission

function onLoad() {
//Type appropriate comment here, and begin script below
var itsegement=g_form.getValue("it_segments");------>it is in parent table
alert(itsegement);
var ga = new GlideAjax('SetValuesforITSDProject');-->my script include
ga.addParam('sysparm_name','myfunction');
ga.addParam('sysparm_user_name',g_form.getValue("it_segments"));
ga.getXML(setValue);
function setValue(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue("short_description",answer);
g_form.setValue("approval_required",'yes');
}}

 

script include:

var SetValuesforITSDProject = Class.create();
SetValuesforITSDProject.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
myfunction: function() {
var name = this.getParameter('sysparm_user_name').toString();
return "test";}

});

kindly help here. Thanks in advance!

1 ACCEPTED SOLUTION

Hi Akash,

If you are having field on child which refers to parent then Have display business rule and set the value in scratchpad variable for it segment.

use this scratchpad variable in onLoad and compare it with your sys id and then set the value for the required fields.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

13 REPLIES 13

Akash68
Kilo Contributor

 

Hi Akash,

If you are having field on child which refers to parent then Have display business rule and set the value in scratchpad variable for it segment.

use this scratchpad variable in onLoad and compare it with your sys id and then set the value for the required fields.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thank you so much:) It is working now.

Haritha Kotturi
Giga Contributor

Hello,

 

You can write after insert/update business rule and get the unique sys_id of parent and child.

and set condition filter as it_segments is 'xyz'.

 

 

var gr = new GlideRecord('child table name');
gr.addQuery('parent',current.sys_id); //querying parent and child sys_id's
gr.query();

while(gr.next()){
gr.setValue('short_description','test');
gr.update(); 

 

 

Thanks.