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

Anurag Tripathi
Mega Patron
Mega Patron

not knowing the names of tables and fields in question its difficult to write code. Plus you wont learn

So Id suggest you write the code and then, if it doesn't work, add here and you will get the help.

-Anurag

(function executeRule(current, previous /*null when async*/ ) {

    var servicetype = current.getValue('u_service_type'); //'service type' field on serviceoffering table
    var Par = current.getValue('parent'); //'parent' field on serviceoffering table
	
    var gr = new GlideRecord('cmdb_ci_service'); //'cmdb_ci_service' is parent table
    gr.addQuery('sys_id', 'Par');
    gr.query();
    while (gr.next()) {
        g_form.setValue(gr.u_service_type,servicetype);
    }

})(current, previous);

This is the script I have tried
service offering(service_offering) table has service type(u_service_type) field and also

Business service(cmdb_ci_service) table also has service type(u_service_type).

So whenever the service type in the service offering table is inserted or updated it should update the same in the business service table service type.

Try this

 

(function executeRule(current, previous /*null when async*/ ) {

    var servicetype = current.getValue('u_service_type'); //'service type' field on serviceoffering table
    var Par = current.getValue('parent'); //'parent' field on serviceoffering table
	
    var gr = new GlideRecord('cmdb_ci_service'); //'cmdb_ci_service' is parent table
    gr.addQuery('sys_id', Par);
    gr.query();
    while (gr.next()) {
        gr.u_service_type = servicetype;
gr.update();
    }

})(current, previous);
-Anurag

Sir, I tried this but whenever service type on service offering changes the immediate parent that is on the business service the service type changes but grand parent and grand grand parent record are not changing

 So any changes to the existing script to be done or another BR on the Business service table to be written.