script to Fetch Incident state from task_sla table.

Roshin Chandra
Tera Contributor
 
5 REPLIES 5

Prince Arora
Tera Sage
Tera Sage

@Roshin Chandra ,

 

 I have tried making a GlideRecord in my PDI as mentioned below:

var gr = new GlideRecord("task_sla");
gr.get("6917ac280b8632007518478d83673ab9");
gs.info(gr.task.state);

 

you can fetch the state of incident using "gr.task.state" or "(gr.task.state).getDislayValue()" as task is the reference field so you can perform dot walking to get the state.

 

PRINCE_ARORA_0-1679422597859.png

 

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

 

 

mattystern
Kilo Sage

@Roshin Chandra 

You can run a background script to do this. See documentation here: Using Scripts - Background 

 

The script below just looks at the first record of task_sla's where the stage is "in progress"

var gr = new GlideRecord('task_sla');
gr.addEncodedQuery("stage=in_progress");
gr.query();
if(gr.next()){
    gs.log("The incident " + gr.task.number + "'s state is " + gr.task.state.getDisplayValue());
}

 Results:

mattystern_0-1679422136553.png

 

AndersBGS
Tera Patron
Tera Patron

Hi @Roshin Chandra ,

 

What is your requirement since you want a script to fetch incident state from task_sla? Could be there where are more standardized solution than custom script?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up,

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

My requirement is to send notification to manger daily regarding all the sla breached tickets whose status is not resolved or closed.