Service Catalog state change between two request - (Second request created from flow)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 10:35 AM
The situation is as follows:
Within one of our instance service catalog items, users can choose a type of request pertaining to the acquisition of one particular item.
They have the option to either request a FIRST device, or submit a request to either acquire a replacement for one that is either defective, lost or stolen.
In the latter case scenario, I use a flow action to submit the return process of the previously owned device if defective. - I found this to be the easiest way to deal with the large quantity of tasks that are subsequently created and need to be processed simultaneously.
I want to be able to give the agent the ability to close or cancel the request as a whole (both REQ tickets) or only partly (Either the "shipping to" request or the "return" request).
To do so, within the catalog item, I provide the agent with a variable that can be checked to specify they want the action of cancelling the request to the whole package of requests or not. - I use this variable in a business rule that runs after the update of an RITM that is either from the main request or the subsequent request as follows:
(function executeRule(current, previous /*null when async*/) {
var is_cancelation = current.variables.u_cancel_request;
var twin_ritm = current.variables.u_twin_ritm;
//Close twin ritm if full cancelation is requested
if(is_cancelation) {
//fetch twin ritm record
var twin_ritm_gr = new GlideRecord("sc_req_item");
twin_ritm_gr.addQuery("sys_id", twin_ritm.sys_id);
twin_ritm_gr.query();
if(twin_ritm_gr.next()) {
//If twin ritm is none of the "complete" state
if(twin_ritm.state != 4 && twin_ritm_gr.state != 3 && twin_ritm_gr.state != 502) {
twin_ritm_gr.state = 502;
twin_ritm_gr.stage = "Request Cancelled";
twin_ritm_gr.update();
}
}
}
})(current, previous);
I believe this code should work as intended, but for some reason regardless of the agent's choice, both requests are cancelled when cancelling one or the other. Is there an OOTB behaviour that I am not aware of that causes this?