Scripting Assignment

Hitesh Ramba
Tera Contributor

HI , I have a requirement using scripting have to make this requirement possible ,kindly help me int it...

 

1.Incident should be auto resolved when all the incident tasks are closed.

2.Incidents should not be allowed to resolve if there are any incident tasks in an open state , and it should throw an alert saying."Please close incident taks",before resolving the incidents.

3.Create a "Best Contact Number" field on the incident form, which should allow only a 10- digit number and auto populate the "Best Contact Number" and "Location" values based on the caller selection from the user tabel.

4.When change is closed all related incident and catalog tasks should be auto-closed and all the worknotes must be updated saying "this has been closed by change rquest : #number."

 

2 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @Hitesh Ramba  ,

I tired your problem in my PDI and it works for me please check kbelow 

 

1.Incident should be auto resolved when all the incident tasks are closed.

var gr = new GlideRecord('incident_task');
gr.addQuery('incident', current.sys_id);
gr.addQuery('state', '!=', 3);
gr.query();

if(gr.next()) {
    gs.addErrorMessage('Incident Can not close because incident task is not closed');
	current.setAbortAction(true);
}else{
	gs.log('close');
	current.setValue('state', 7);
}

 

2.Incidents should not be allowed to resolve if there are any incident tasks in an open state , and it should throw an alert saying."Please close incident taks",before resolving the incidents.

var gr = new GlideRecord('incident_task');
gr.addQuery('incident', 'current.sys_id');
gr.addQuery('state', 1); // open
gr.query();
if(gr.next()) {
    gs.addErrorMessage('Please close incident taks,before resolving the incidents.' );
	current.setAbortAction(true);
}
else{
	current.state = 6 // resolved
}

 

4. When change is closed all related incident and catalog tasks should be auto-closed and all the worknotes must be updated saying "this has been closed by change rquest : #number."

var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
    var incgr = new GlideRecord('incident');
    incgr.addQuery('parent', current.sys_id);
    incgr.query();
	gs.print(incgr.getRowCount());
    while(incgr.next()){
		incgr.setValue('state', 7);
		incgr.setValue('comments','this has been closed by change rquest by ' + current.number);
	}

	var taskgr = new GlideRecord('sc_task');
    taskgr.addQuery('parent', current.sys_id);
    taskgr.query();
	gs.print(taskgr.getRowCount());
    while(taskgr.next()){
		taskgr.setValue('state', 3)
		taskgr.setValue('comments','this has been closed by change rquest by ' + current.number);
	}
	current.state = 6;
}

 

Please mark my answer correct and helpful if this works for you 

 

Thanks and Regards 

Sarthak

View solution in original post

Hi @Hitesh Ramba  

 

You need to use when to run as before  and update 

 

 

Thanks and Regards

Sai Venkatesh

View solution in original post

12 REPLIES 12

Hi, the first code is working for me and table to select on business rule is "incident"

 

 

Thanks and Regards

Sai Venkatesh

Community Alums
Not applicable

Hi @Hitesh Ramba  ,

Condition for business rules is like 1st and 2nd are before update business rules on incident table and the 4th is before update on change_request table

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

Hi @Community Alums  I am trying 1st one from a long time but its not at all working , can you help me ...
I have added incident task -> incident in the related list of incident form and created 2 tasks and made them closed compltetd state .But The incident is not changing ..

Please help

 

Thank You!

Community Alums
Not applicable

Hi @Hitesh Ramba  ,

Can you please share me some images for reference, I'll check that.

 

Thanks!

Sure , Check the screenshots