- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2021 09:27 AM
Hi All
I have a requirement that says whenever the "Service Type" field on the service offering table(child table) is inserted or updated.
on the parent table called "Business Service " the "Service Type" field should be updated with the same as the child table's "service type" value
Can someone provide me a solution..???
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 04:01 AM
Dot walk and update doesn't work, you have to GlideRecord to parent record and update it.
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type');
if (JSUtil.notNil(current.parent)){
var gr = new GlideREcord('<parent table>');/add the table name here
gr.addQuery('sys_id',current.parent )
gr.query();
if(gr.next())
{
gr.u_service_type = servicetype;
gr.update();
}
})(current, previous);
The condition of the BR should be that current.parent is not empty AND current.u_service_type Changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 01:27 AM
Id suggest having a separate BR because this seems like a separate logic than the original one.
But be very cautions as this might go in infinite loop. So test well in sub prods.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 01:35 AM
So that BR would be on cmdb_ci_service table and what would be the logic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 03:42 AM
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type');
if (JSUtil.notNil(current.parent)){
current.parent.u_service_type = servicetype;
update();
}
})(current, previous);
I have used this script to update the parent and grandparent on cmdb_ci_service table its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 04:01 AM
Dot walk and update doesn't work, you have to GlideRecord to parent record and update it.
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type');
if (JSUtil.notNil(current.parent)){
var gr = new GlideREcord('<parent table>');/add the table name here
gr.addQuery('sys_id',current.parent )
gr.query();
if(gr.next())
{
gr.u_service_type = servicetype;
gr.update();
}
})(current, previous);
The condition of the BR should be that current.parent is not empty AND current.u_service_type Changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2023 08:02 AM
Hope your issue is fixed by now, but overall when I see your script, you used, g_form in a BR, but it is a client side API. Please make note of that.
Best Regards,
Pratyusha