Business rule to set a field value

Appu
Tera Guru

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

1 ACCEPTED SOLUTION

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

-Anurag

View solution in original post

11 REPLIES 11

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.

-Anurag

So that BR would be on cmdb_ci_service table and what would be the logic

 

(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.

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

-Anurag

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