- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 10:12 PM
1) when i update the state of sctask to any, then I need to update the state of RITM and REQ and Universal request too?
2) When I update the work notes or additional comments of sctask it should update on RITM and on Universal request too?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2022 03:10 AM
It's working now like this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedCompleteCount = 0;
var closedInCompleteCount = 0;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.query();
var totalCount = gr.getRowCount();
while(gr.next()){
if(gr.state == 3){
closedCompleteCount++;
}
if(gr.state == 4){
closedInCompleteCount++;
}
}
var ritm = current.request_item.getRefRecord();
var req = current.request.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.update();
req.state = 3;
req.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.update();
req.state = 4;
req.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2022 11:56 PM
First thing that you need to have an After update BR rule with condition work notes changes on sc_task table which passes those information in RIT and UR.
Another After update BR rule with condition state changes to closed on sc_task table which sets the RITM, Request and UR as closed.
Its pretty simple gliderecord query, for each table in the BRs, try it out and share with us.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 12:07 AM
To update the state of req and ritm i have done this and in the state mapping of universal request i have mentioned that when the state changes of its primary ticket (RITM), then universal request state will be changed. But the thing is Req state is not changing.
here is the written code :
BR is after
condition is state is one of closed complete or closed incomplete
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedCompleteCount = 0;
var closedInCompleteCount = 0;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.query();
var totalCount = gr.getRowCount();
while(gr.next()){
if(gr.state == 3){
closedCompleteCount++;
}
if(gr.state == 4){
closedInCompleteCount++;
}
}
var ritm = current.request_item.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.update();
}
})(current, previous);
And, next thing is, i have written code to update the worknotes of RITm and universal request , but i don't know how to update the universal request worknotes through code. so i need help over here too
Here is the code :
BR is before insert or update
conditon is worknote/additional comments changes
(function executeRule(current, previous /*null when async*/)
{
var com = "Catalog Task Comments for " + current.number + " : " + current.comments;
var v_gRITM = new GlideRecord('sc_req_item');
v_gRITM.addQuery('sys_id', current.request_item);
v_gRITM.query();
if (v_gRITM.next())
{
v_gRITM.comments= current.comments;
v_gRITM.work_notes= current.work_notes;
v_gRITM.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2022 12:58 AM
For your 1st issue, the closure of RITM should result in closure of Request as well, that is administered by OOB BR "Close Parent if Required" and check the condition for these, probably you will have to make changes to your first script to update stage as well.
For your 2nd issue, you can find your way from Universal request using Primary ticket field on the form and using that you can pass on information from catalog task to UR
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 03:57 AM
Hello
I need your help for the below script. It's working fine for closing ritm if all the sc_task under it closed. along with that i need to close REQ.
How and where can i add the script in the below mentioned script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var closedCompleteCount = 0;
var closedInCompleteCount = 0;
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.query();
var totalCount = gr.getRowCount();
while(gr.next()){
if(gr.state == 3){
closedCompleteCount++;
}
if(gr.state == 4){
closedInCompleteCount++;
}
}
var ritm = current.request_item.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2022 06:26 AM
I have already shared that, you have to follow "Close Parent if Required". no changes are required, so just have to additionally set the stage field of the ritm as complete or closed_incomplete.
Update the script in these lines:
var ritm = current.request_item.getRefRecord();
if(totalCount == closedCompleteCount){
ritm.state = 3;
ritm.stage = "complete";//update stage on RITM as complete
ritm.update();
}
if(closedInCompleteCount > 0){
ritm.state = 4;
ritm.stage = "closed_incomplete";//update stage on RITM as incomplete
ritm.update();
}
Aman Kumar