The CreatorCon Call for Content is officially open! Get started here.

Is it feasible to close PROBLEM while auto closing PTASK

Vijaykumar K
Tera Contributor

Hi all,

 

I have a schedule job to run and close all PTASK if there is no update more than 30 days and it's working. My request is, is it possible to close associated PROBLEM ticket while closing PTASK.

I have tested reverse chronological I.e auto close PTASK while closing PROBLEM and it's working . But client requirements is reverse   functionality, auto close associated PROBLEM while auto closing PTASK. ? Pls confirm if we can do this?

 

Many Thanks 

5 REPLIES 5

Saurabh Gupta
Kilo Patron

Hi,
This can be done using the same scheduled job, you need to just add a script after closing the all ptask.

 

 


Thanks and Regards,

Saurabh Gupta

Aman Kumar S
Kilo Patron

Hi @Vijaykumar K 

Can you add the logic in form of a function, you can run the job to check if all the PTasks are closed then close the problem task.

Try below code in scheduled job:

var grProblem = new GlideRecord("problem");

grProblem.addActiveQuery();

grProblem.query();

while(grProblem.next()){

    var grPTask = new GlideRecord("problem_task");

    grPTask.addQuery("problem", grProblem.getUniqueValue());

    grPtask.addActiveQuery();

    grPtask.query();

    if(!grPtask.next()){

        grProblem.setValue("state",3);

        grProblem.comments = "Closing problem ticket since all problem tasks are closed";
        grProblem.update();

     }

}

 

Best Regards
Aman Kumar

Hi @Aman Kumar S  I'm using attached script in schedule job. It's not working as expecting. What I observed is , once run the SJ,  which ever PTASK state is 152 they are getting closed but all the PROBLEM tickets also getting closed( all avail problem tickets in instance).

My request is that , the associated PROBLEM only should close whiche closing PTASK.  Can you pls check and help.

 

Many thanks

Hi @Vijaykumar K 

You just need to readjust the code a bit:

 

var grProblem = new GlideRecord("problem");
grProblem.addActiveQuery();
grProblem.query();
while(grProblem.next()){
    var ga = new GlideAggregate("problem_task");
    ga.addQuery("problem", grProblem.getUniqueValue());
    ga.addAggregate("COUNT");
    ga.query();
    if(ga.next()){
       var count = ga.getAggregate("COUNT");
       if(count>0){
           var grPTask = new GlideRecord("problem_task");
           grPTask.addQuery("problem", grProblem.getUniqueValue());
           grPTask.addActiveQuery();
           grPTask.query();
           if(!grPTask.next()){
             grProblem.setValue("state",3);
             grProblem.comments = "Closing problem ticket since all problem tasks are closed";
             grProblem.update();
             gs.info(grProblem.getValue("number"));
           }
       }
   }

}

Feel free to mark apt response as Helpful and Correct so thread can be close, and makes it easier for others to spot the answer looking for similar issue. 

Help make community better!

 

Best Regards
Aman Kumar