closing of problem record only when all the problem tasks are closed

msc
Tera Contributor

Hi everyone,

In problem record , problem record will  be closed only  when all the ptasks are closed complete. before the record is closed  then a message should be display please close the ptask .

if we cancel the problem record then all the problem task will  be changed to closed complete auttomatically.

9 REPLIES 9

Aman Singh_
Kilo Sage

Hi,

 

Create a before Update BR on Problem table with condition as

Problem Status changes to closed

 

and use the following in script

var gr = new GlideRecord('problem_task');
      gr.addQuery('active','true');
      gr.addQuery('problem',current.sys_id);
      gr.query();

  if (gr.next()) {
    gs.addInfoMessage(gs.getMessage("A task is open. Please complete the task before closing the problem ticket."));
    current.setAbortAction(true);
  }

 

Mark Correct/helpful, if applicable, Thanks!!

Aman

msc
Tera Contributor

if we cancel the problem record then all the problem tasks will  be changed to closed complete auttomatically.

If you have the Cancel UI Action follow what Ankur suggested.

Your initial query is answered, close the thread by marking appropriate answer as correct.

 

Just a suggestion, try to build it by yourself if they are your assignments during your training period.

 

Thanks,

Aman

Ankur Bawiskar
Tera Patron
Tera Patron

@msc 

for this point

if we cancel the problem record then all the problem task will  be changed to closed complete auttomatically.

I assume you must be having Cancel UI Action on Problem table

Server Side Script in UI Action:

(function(){

	try{
		// your code
		var gr = new GlideRecord("problem_task");
		gr.addQuery("problem", current.getUniqueValue());
		gr.query();
		while(gr.next()) {
			gr.state = 157; // closed
			gr.update();
		}
	}
	catch(ex){
		gs.info(ex);
	}

})();

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader