I want to link the State of RITM with the State of SCTASK.

Yugo Sakuma
Tera Contributor

I currently set the following business rules.

 

var taskGr = new GlideAggregate('sc_task');
taskGr.addAggregate('COUNT');
taskGr.addQuery('request_item', current.getUniqueValue());
taskGr.addActiveQuery();
taskGr.query();
taskGr.next();

if (taskGr.getAggregate('COUNT') > 0) {
    current.setAbortAction(true);
	gs.addErrorMessage("[状況]を更新できません。画面をリフレッシュすると元の値に戻ります。SCTASKを全てクローズすると[状況]は自動で更新されます。");
}

 

For this script, I'd like to add a restriction that RITM's [State] cannot be changed to [Open] or [Work in Progress] when all SCTASK's [Status] are [Closed(Complete, Incomplete, Skipped)], and a rule that automatically updates RITM's [State] to [Work in Progress] if even one SCTASK's [State] is not [Closed(Complete, Incomplete, Skipped)]

I would like to know a good solution for coding to add the above settings without changing the original script content.

1 ACCEPTED SOLUTION

Hi @Yugo Sakuma,

You may try the following Fix script to achieve the requirement.

1.when any of task is in open/in progress then state field remain as decided in flow once all taks done then RITMs state changes to closed complete.
please refer the following script for better understanding.

var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('stateIN-5,1,2');
gr.query();
while(gr.next())
{
var cnt = 0;
var gr_task = new GlideRecord('sc_task');
gr_task.addQuery('request_item',gr.sys_id);
gr_task.query();
while(gr_task.next())
{
if(gr_task.state == '-5' || gr_task.state == '1' || gr_task.state == '2' )
{
cnt++;
break;
}
}
if(cnt == 0)
{
gr.state = '3'; // once all the task state is complete/incomplete/skipped then here set the state as per requirement '3' is referring to closed complete.
gr.update();
}
}


2.For Read only You may use the UI policy. Attaching screenshot for reference.

 

community_12.PNGcommunity_13.PNG

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi

View solution in original post

8 REPLIES 8

Hi @Rohit99 

 

Thank you very much.

I will try to implement it in the way you suggested.

 

Yugo Sakuma

Hi @Yugo Sakuma ,

Have you tried the given solution ?

Let me know if you have any questions.


Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi

Yugo Sakuma
Tera Contributor

Hello @Jitendra Diwak1 

Thank you for your reply

 

We have already set up a specific flow for the catalog items associated with this RITM and SCTASK.
This business rule is intended to control when a State is manually changed while the flow “Wait for Condition” is waiting for 14 days.

Hi @Yugo Sakuma,

 

Is there any assistance is required or we can close this thread.

 

Please accept my solution if it works for you and thumps up

 

Thanks

Jitendra 

Please accept my solution if it works for and thumps up.