Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Copy short_description From "csdm_ci_service" to short_description in child "service_offering"

ronro2
Tera Contributor

Hey guys! 

As the title implies, I need help with copying the short_description of the parent (cmdb_ci_service) business service and fill in the same information in the child service offering (service_offering) field called short_description. 

This is my Business Rule which is not working: 

(function executeRule(current, previous /*null when async*/) {
    // Skapa en GlideRecord för att hämta värdet från huvudärendet
    var parentRecord = new GlideRecord('cmdb_ci_service');
    if (parentRecord.get(current.parent)) {
        // Kopiera värdet från huvudärendets short_description till barnets short_description
        current.short_description = parentRecord.short_description;
    }
})(current, previous);

 

ronro2_0-1745853480505.png

 

What am I doing wrong? 

Thanks in advance guys!

1 ACCEPTED SOLUTION

@ronro2 

That's correct a business rule will only work when you update the form

If you want to see the field with real-time data being fetched then you can use onLoad client script + GlideAjax

OR Another way

you can use display business rule on service_offering table

Script:

current.short_description = current.parent.short_description;

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

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@ronro2 

script looks fine

is it going inside the IF?

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

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

@Ankur Bawiskar This is what the whole script looks like. It's just not working. Keep in mind that the short_description field in the parent is not the same as the short_description field in the child, even though they have the same name. 

ronro2_0-1745868281658.png

 

@Ankur Bawiskar never mind! It works after updating/saving the form. I think a client script with glideAjax might be a better solution for direct copying, right? 

@ronro2 

That's correct a business rule will only work when you update the form

If you want to see the field with real-time data being fetched then you can use onLoad client script + GlideAjax

OR Another way

you can use display business rule on service_offering table

Script:

current.short_description = current.parent.short_description;

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

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