Issue with Updating "short_description" Field from Parent to Child in ServiceNow

ronro2
Tera Contributor

Hi!

In servicenow I have a little problem with updating a field short_description from parent (cmdb_ci_service) to child (service offering).

This is my before insert/update Business Rule (based on cmdb_ci_service): 

(function executeRule(current, previous /*null when async*/) {
// Query for all children that reference this parent
var grChild = new GlideRecord('service_offering');
grChild.addQuery('parent', current.sys_id);
grChild.query();

while (grChild.next()) {
grChild.short_description = current.short_description;
grChild.update();
}
})(current, previous);

 

I have this Script include with Script Include reference (based on service_offering table):

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var ga = new GlideAjax('GetParentShortDescriptionCSDM');
ga.addParam('sysparm_name', 'getShortDescription');
ga.addParam('sysparm_parent_id', newValue);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('short_description', response);
}
});
}


Here is the Script Include itself: 

var GetParentShortDescriptionCSDM = Class.create();
GetParentShortDescriptionCSDM.prototype = Object.extendsObjectvar (AbstractAjaxProcessor, {

getShortDescription: function() {
var parentSysId = this.getParameter('sysparm_parent_id');
if (!parentSysId) return '';

var gr = new GlideRecord('cmdb_ci_service');
if (gr.get(parentSysId)) {
return gr.short_description.toString();
}

return '';
}

});


The issue is that it works fine with already created posts in the service_offerint table (the short_description field gets updated with the same value that is in parent's short_description field). 

But when I create a new post on service_offering table, via related list on parent, that is not yet submitted, the short_description field stays empty even though the parent short_description field contains a value. 

What could be the problem? That I need another business rule that is of type before insert on the child table (service_offering)?  

Thanks in advance!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@ronro2 

it should work during insert as well

Did you check what's the value of parent.short_description when your BR runs?

OR

You can use flow designer for this with Insert & Update logic and handle the copy of field

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@ronro2 

it should work during insert as well

Did you check what's the value of parent.short_description when your BR runs?

OR

You can use flow designer for this with Insert & Update logic and handle the copy of field

If my response helped please mark it correct and close the thread so that it benefits future readers.

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