- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 07:03 AM - edited 04-29-2025 11:37 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 08:05 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2025 08:05 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader