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

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

Hi Sarthak , I hope the code works but you didnt mention the conditions when to apply , like before or after 

Hi @Hitesh Ramba  

 

You need to use when to run as before  and update 

 

 

Thanks and Regards

Sai Venkatesh

Hi @SAI VENKATESH  For all the three?
Also have you checked the 1st code , its not working for me .What is the table I need to mention in the bussiness rule table name?