- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 02:56 PM
When the state field changes in RITM then, REQ state needs to be changed.
RITM States: REQ States :
Open Pending Approval.
Closed Complete. Approved, Closed Complete
Closed Incomplete Closed Incomplete, Closed Cancelled, Closed Rejected
Closed Skipped Closed Skipped
For Approval the state changes works fine, But not for the rejection alone.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2020 03:06 PM
Is Request and Requested Item always a one-to-one? If not, I think there is a better solution.
If it is a one-to-one your script works with a few tweaks:
Create an After Update Business rule on the Requested Item with following code:
(function executeRule(current, previous /*null when async*/) {
var request = new GlideRecord('sc_request');
request.get(current.request)
if (current.state == '3') {
request.active = false; // set active to false
request.request_state = '3'; // Set state to closed Complete
request.update();
}
else if (current.state == '4') {
request.active = false; // set active to false
request.request_state = '4'; // Set state to closed Incomplete
request.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-11-2020 04:07 PM
Checked all the BR, Seems like there is something setting all the REQ to Approved.
Trying to write a BR for updating the REQ from RITM state changes.
(function executeRule(current, previous /*null when async*/) {
//if (current.variables.select_one != 'Single CI Update')
var req = current.request;
var i = 0, j = 0, k = 0;
var appr, state;
var gr =new GlideRecord('sc_req_item');
gr.addQuery('request', req);
gr.query();
var count = gr.getRowCount();
while(gr.next())
{
if (gr.approval == 'approved')
{
i++;
}
if (gr.approval == 'rejected')
{
j++;
}
if (gr.approval == 'cancelled')
{
k++;
}
}
if (count == i && count!= 1)
{
RequestState('approved', 'closed_complete');
}
if (j == count-1 && count!= 1)
{
RequestState('rejected', 'closed_rejected');
}
if (k == count-2 && count != 2)
{
RequestState('Cancelled', 'closed_incomplete');
}
function RequestState(appr, state)
{
var gr1 = new GlideRecord('sc_request');
gr1.addQuery('sys_id', req);
gr1.query();
if (gr1.next())
{
gr1.approval = appr;
gr1.request_state = state;
gr1.update();
}
}
})(current, previous);
Approval and Rejection works fine, Need help on Cancelling.