Business Rule not working

SanthoshKumar R
Tera Contributor

Hi Community, I have written a BR to change state of related incidents to resolved when problem is resolved and to copy the fix notes field from problem to resolution notes in associated incidents.  But it is not working can anyone please give the solution for this?

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

    // Add your code here
    var problem=current.sys_id;
    var inc=new GlideRecord('incident');
    inc.addQuery('problem_id',problem);
    inc.query();
    while(inc.next())
    {
         inc.setValue('state','6');
        inc.setValue('close_notes',current.fix_notes);
       
    }

})(current, previous);
1 ACCEPTED SOLUTION

Hi @SanthoshKumar R,

 

Try this updated scripts and your business rule condition should state changes to resolved:

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

	var problem = current.getUniqueValue();
	
	var inc = new GlideRecord('incident');
	inc.addQuery('problem_id', problem);
	inc.query();
	while (inc.next()) {
		inc.setValue('state', '6');
		inc.setValue('close_notes', current.description);
		inc.setValue('close_code', 'Resolved by problem: ' + current.number);
		inc.setWorkflow(false);
		inc.autoSysFields(false);
		inc.update();
		
	}

})(current, previous);

 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

View solution in original post

7 REPLIES 7

@SanthoshKumar R can you please share the BR conditions and the script here

 

BR to change state of related incidents to resolved when problem is resolved and to copy the fix notes field from problem to resolution notes in associated incidents.
as per you guidence I tried another field but it is creating new incident with updated data


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

    // Add your code here
    var problem=current.sys_id;
    var inc=new GlideRecord('incident');
    inc.addQuery('problem_id',problem);
    inc.query();
    while(inc.next())
    {
        inc.setValue('state','6');
        inc.setValue('close_notes',current.description);
        inc.setValue('close_code','Resolved by problem');

        //inc.state=6;
    }
    inc.update();
    //inc.setWorkflow(false);

})(current, previous);

 

Hi @SanthoshKumar R,

 

Try this updated scripts and your business rule condition should state changes to resolved:

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

	var problem = current.getUniqueValue();
	
	var inc = new GlideRecord('incident');
	inc.addQuery('problem_id', problem);
	inc.query();
	while (inc.next()) {
		inc.setValue('state', '6');
		inc.setValue('close_notes', current.description);
		inc.setValue('close_code', 'Resolved by problem: ' + current.number);
		inc.setWorkflow(false);
		inc.autoSysFields(false);
		inc.update();
		
	}

})(current, previous);

 


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow