Moving variable change from child to parent

Kate Salamoun
Tera Contributor

Good Morning,

            I have two custom tables currently. The record producer I have writes a record to table 1 and the workflow contained in it also spawns off a task to table 2. I have managed to map variables from the parent (table 1) to the child (table 2) but I am needing to make it so that when I change a field in the child it will map up to the parent. I tried to use a business rule: parent.variables.u_subaccount = current.subaccount - However this is not mapping the field. Any suggestions would be greatly appreciated.

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If you're setting a value on a variable associated with the parent record from the child record, you can't dotwalk, you have to use GlideRecord. Something like this should work:

var parentRecord = new GlideRecord('name_of_parent_table');

if (parentRecord.get(parent.getValue('sys_id')) {

    parentRecord.variables.u_subaccount = current.subaccount;

    parentRecord.update();

}

 

Here is what I tried:

function executeRule(current, previous /*null when async*/) {
	var parentRecord = new GlideRecord('u_invoice_approvals');
	if (parentRecord.get(parent.getValue('sys_id'))) {
		parentRecord.variables.u_subaccount = current.u_subaccount;
		parentRecord.update();
	}
}

 

Still no go 😞

Let's validate some things.

Does the child table have a field named 'parent' that references the parent table or is it called 'u_parent'? 

Is the u_subaccount on the child table a field or a variable? If it's a variable that line will need to be:
parentRecord.variables.u_subaccount = current.variables.u_subaccount;

You might also add some logging in there to see if it gets inside the if statement and to make sure that everything has values.

The child table has a field that links to the parent field. The u_subaccount is a field on the child table that when its created the value is being pulled from the parent table. On the parent table this is a variable that is being filled from the record producer. the Subaccount also references the cmn_cost_center.