- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 09:37 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 02:44 AM
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.
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 10:05 PM
Hi @Yugo Sakuma,
it is requested to set the RITM values from workflow/flow designer and this is the best practice. Once the task is closed incomplete or rejected or cancelled then it should be greyed out the state field on RITM and rest you do not need to create any BR to sync the state which can be easily handled by workflow/flow designer.
Please accept my solution if it works for you and thumps up.
Thanks
Jitendra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 10:52 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 05:20 PM
Hi @Rohit99
Yes, I am.
I would like to implement ’State’ control of already created RITM and SCTASK tickets with the aforementioned specifications.
Thank you
Yugo Sakuma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 02:44 AM
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.
Please mark my response as correct and helpful if it helped solved your question.
Thanks,
Rohit Suryawanshi