Setting Priority on SCTASKs

Christine24
Giga Expert

I'm trying to write a script to set Priority on Service Catalog tasks. We have a form that asks about Impact/Urgency and when I tried to set Priority with a script, nothing happens. Originally I tried to just set the Impact and Urgency with my script so that I could use Priority Lookup Rules, but that did not seem to work. I then tried to make a script using our Priority matrix, but that's not setting anything either.

Here is my current script (but I would love to go back to the original plan of just mapping Impact/Urgency and then having the Lookup Rules set Priority):

if(current.variables.impact == 1 && current.variables.urgency == 1)
    {
        current.sc_task.priority.Value = 1;
    }

else if(current.variables.impact == 2 && current.variables.urgency == 1)
    {
        current.sc_task.priority.Value = 2;
    }

else if(current.variables.impact == 3 && current.variables.urgency == 1)
    {
        current.sc_task.priority.Value = 3;
    }
else if(current.variables.impact == 1 && current.variables.urgency == 2)
    {
        current.sc_task.priority.Value = 2;
    }
else if(current.variables.impact == 2 && current.variables.urgency == 2)
    {
        current.sc_task.priority.Value = 3;
    }
else if(current.variables.impact == 3 && current.variables.urgency == 2)
    {
        current.sc_task.priority.Value = 4;
    }
else if(current.variables.impact == 1 && current.variables.urgency == 3)
    {
        current.sc_task.priority.Value = 3;
    }
else if(current.variables.impact == 2 && current.variables.urgency == 3)
    {
        current.sc_task.priority.Value = 4;
    }
else if(current.variables.impact == 3 && current.variables.urgency == 3)
    {
        current.sc_task.priority.Value = 4;
    }

2 REPLIES 2

Chavan AP
Tera Guru

hey hi Christine

i have reproduced your requirement in my personal instance as below in it worked as expected.

Added below two variables to get impact and urgency in catalog item

 

find_real_file.png

 

now as per your requirement you want to update the priority of catalog task, so ether you can write a BR on sc_task table or you can write a script in workflow itself

 

try below script it worked for me:

var gr = new GlideRecord('sc_req_item');
gr.addQuery('sys_id','fd854303db2640109648196c29961966'); //RITM sys_id
gr.query();
while(gr.next()){
gs.log("Impact is: "+gr.variables.impact) ;
gs.log("Urgency is: "+gr.variables.urgency);
	
	if(gr.variables.impact == 1 && gr.variables.urgency == 1)
    {
       current.sc_task.priority.Value = 1;
		gs.log('priority is 1');
    }

else if(gr.variables.impact == 1 && gr.variables.urgency == 2)
    {
        current.sc_task.priority.Value = 2;
		gs.log('priority is 2');
    }
	
		current.update();
}

 

Output SS:

find_real_file.png

 

feel free to ask incase of any query.

 

Please mark correct and helpful if this resolves your query

 

regards,

ajay

 

Chavan AP
[ Architect | Certified Professional]

Was this response helpful? If so, please mark it as ✅ Helpful and ✅ Accept as Solution to help others find answers.

So I gave that a try and it is still not working. I did put it in my workflow (as run script) and got an error for current.update() which I then removed. It warned me of an endless loop which I didn't want to mess with. Any thoughts?