- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 11:41 PM
Hi all,
I have created an order guide, and it contains four different catalog items, each of which follows a different flow. I have used flow design. Now, I want to check the status of each RITM, and if the state and stage of all four RITMs are complete, then I need to update the REQ record for those RITMs. How can I achieve this?
Thanks in advance!
@Ankur Bawiskar @Rahul Talreja @Pavankumar_1 @Samaksh Wani @Vishal Birajdar @Dr Atul G- LNG @Hemanth M1 @Saurabh Gupta @Sagar Pagar @Aman Kumar S
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 12:17 AM
Hi @Priya Rao
Ok so yo need write Business rule as below on RITM table :
(function executeRule(current, previous /*null when async*/ ) {
/* 1. Get the request from current form */
var request = current.request;
/* 2. Glide Record on Request item table & check if there is any RITM which is not in closed complete state */
var grItem = new GlideRecord('sc_req_item');
grItem.addEncodedQuery('request=' + request + '^state!=3');
grItem.query();
if(!grItem.next()){
/* update request record */
var grReq = new GlideRecord('sc_request');
grReq.addQuery('sys_id',request);
grReq.query();
if(grReq.next()){
// set values on request
grReq.state = 3;
grReq.update();
}
}
})(current, previous);
Hope this helps....!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 01:03 AM - edited 10-06-2023 01:04 AM
var request = current.request;
var grRITM = new GlideRecord('sc_req_item');
grRITM.addEncodedQuery('stateNOT IN3,4,7^request=' + request);
grRITM.query();
if (!grRITM.hasNext()) {
var req = new GlideRecord('sc_request');
req.get(request);
req.state = ''; //Update according to your requirement
}
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 07:56 AM
Hi @Priya Rao ,
Create after business rule on RITM table and select update and give condition as when state changes to closed complete. In advance use below script
Script:
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('request',current.request); //get RITMS only for the same request
grRITM.addEncodedQuery('state!=3');//state is not closed complete
grRITM.query();
if (!grRITM.next()) {//if we don't have any RITM other than close complete
var grReq = new GlideRecord('sc_request');
if(grReq.get(current.request)){
grReq.stage = 'closed_complete'; //give your stage value
grReq.update();
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 11:45 PM
Hi @Priya Rao
As its order guide , then there will be only one Request will be created for all four RITMS.
May be can you provide some screenshot for more clarity.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2023 11:53 PM
Hi @Vishal Birajdar ,
Based on the state of these 4 RITM's, (I'll be closed complete) I need to update the state of the REQ to Complete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 12:17 AM
Hi @Priya Rao
Ok so yo need write Business rule as below on RITM table :
(function executeRule(current, previous /*null when async*/ ) {
/* 1. Get the request from current form */
var request = current.request;
/* 2. Glide Record on Request item table & check if there is any RITM which is not in closed complete state */
var grItem = new GlideRecord('sc_req_item');
grItem.addEncodedQuery('request=' + request + '^state!=3');
grItem.query();
if(!grItem.next()){
/* update request record */
var grReq = new GlideRecord('sc_request');
grReq.addQuery('sys_id',request);
grReq.query();
if(grReq.next()){
// set values on request
grReq.state = 3;
grReq.update();
}
}
})(current, previous);
Hope this helps....!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 05:21 AM
@Vishal Birajdar , Thanks for your response. I tried with this but it's not setting the state of the REQ to Closed Complete when all the RITM's are closed.