setting incident to active false

Rahul Raja Sami
Tera Guru

Hi I have created a BR on request table, where it checks whether its parent is empty or not.

if not empty then it glide incident table and check for the concerned parent incident and sets it state to request created.
upto this is fine, but I want to set the incident active to false along with its state.

var gr = new GlideRecord('incident');
	gr.addQuery('sys_id',current.parent);
	
	gr.query();
	if(gr.next()){
		gr.state = '9';
		gr.active = false;
gr.work_notes='Incident converted to request \n Kindly access Request from Related List';
		gr.update();
	}

this is changing the state but not setting the active to false.
what to do?

1 ACCEPTED SOLUTION

When I tested this and got it to work, I did the condition on the first tab..."when to run" via the GUI, not on the advanced tab. The advanced tab condition is still "current.incident_state != IncidentState.CLOSED && current.incident_state != IncidentState.CANCELED"

jMarshalatuLe_0-1684947023475.png

^^ I already deleted the custom state in my PDI before I took this screener, but I did this with a custom state of "Request created"

View solution in original post

29 REPLIES 29

Hi,

instead of updating the close code and notes why can't we update the data policy like canceled state?

You may be able to do it with a data policy too -- but you definitely need the condition on the "incident reopen" BR, so that it doesn't trigger when you adjust the record (because it is a "before update" BR, it'll do the work it is trying to do first)

it is working, but why it is showing the data policy exception for the new state and not for canceled state.?

Joe S1
Kilo Sage

Hello Rahul,

 

There are a couple out of the box things in play here that are preventing you from moving the active flag to 'false'. First since the Request Created is a custom value and is not technically a valid closed state this business rule is automatically flipping the active flag from "false" back to "true"

JoeS1_0-1684944172763.png

If you update the condition on that BR to include the Request Created state, you will then have a conflict with an out of the box data policy that requires Resolution code and Resolution notes to be populated. So in your script you'll need to populate those values as well in order for the updates to the record to occur.

var gr = new GlideRecord('incident');
	gr.addQuery('sys_id', current.parent);
	
	gr.query();
	if(gr.next()){
		gr.state = '9';
		gr.active = false;
        gr.close_code = 'Resolved by request';
        gr.close_notes = 'Incident converted to request';
        gr.work_notes='Incident converted to request \n Kindly access Request from Related List';
		gr.update();
	}

oops, I'm too slow haha