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

Did you try in BG scripts or modifying your BR and running on demand? Also @Steven Parker solution should totally work, but for the modified condition on the BR to work, do make sure you are putting the name of the custom state you created (value = 9) in ALL_CAPS_WITH_UNDERSCORES_NOT_SPACES -- not always obvious, IMO

yes I tried in my BG and also updated my BR. i am seeing no error and even when I run the BG script i can see this

RahulRajaSami_0-1684943753262.png

but the incident is not updated.

I tested this against the sc_task table and your script works...further, it triggers an oob BR which changes the state of the TASK also.

I have the same results against incident, as you're experiencing...so, I would definitely say this has to do with a BR looking @ incident state and setting it to "active" because it isn't "closed" or "cancelled".

I did a bit of digging on my PDI and found a BR called "incident reopen", which is doing a before update action, where 'active = false' and has the conditions @Steven Parker mentions here. I added the condition for "State does not equal <custom state>" and it seems to work, but also wants a close code and resolution note...so as long as you satisfy those conditions, this should work. I'd recommend modifying both the "incident reopen" and "mark closed" ones.

FYI, I tested it and this works in BG scripts after adjusting the "incident reopen" BR that I described above.

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0010001');

gr.query();
if(gr.next()){
gr.active = 'false';
gr.state = '9';
gr.close_code = 'No resolution provided';
gr.close_notes = 'test';
gr.update();
}

 

Note - this works with or without quotes on "gr.active = false"

made change in incident re open and tried your script as well but not working