- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 01:04 AM
Hi,
When the request is raised, corresponding request item is not getting approved. I can see that, ServiceNow has a in-built business rule "Cascade Request Approval to Request Item", which will automatically approve the underlying request items, when a request is approved.
When the request is approved, though this business rule is getting executed, It's not making the request item to approved. I put up few log statements. In Line no. 25, before updating the record, it has correct workflow stage. But after this line is executed, it's setting back to previous stage itself. It's not throwing any errors as well in Try..catch statements.
/**
* The Request has been approved, rejected or cancelled. Propogate this state
* change down to the request items.
*/
cascadeRequestApproval();
function cascadeRequestApproval() {
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while (gr.next()) {
// We handle this differently for delivery plans vs. workflows
try
{
if (gr.cat_item.workflow && !gr.cat_item.workflow.nil())
{
gs.log("1.Worflow exists for BYOD item. Cascading approval to request item");
cascadeRequestApprovalWorkflow(gr);
}
else
cascadeRequestApprovalDeliveryPlan(gr);
gs.log("4.Cascade Request Item approval status to be updated to " + gr.stage + " step");
gr.update();
gs.log("5.Cascade Request Item approval status is updated to " + gr.stage + " step"); }
catch(err) {
gs.log("6.Error in cascade catalog item approval business rule: " + err);
}
}
}
/**
* Cascade the request approval to the request item:
*
* approved -> if item is waiting for approval, get first stage of the delivery plan
* rejected -> mark item as Request Cancelled
*/
function cascadeRequestApprovalDeliveryPlan(gr) {
if (gr.cat_item.delivery_plan.nil())
return;
gr.approval = current.approval;
if (gr.stage == "waiting_for_approval" && current.approval == "approved")
gr.stage = getNextStage(gr);
else if (current.approval == 'rejected')
gr.stage = 'Request Cancelled';
}
function cascadeRequestApprovalWorkflow(gr) {
gs.log("2.Cascade test: Stage: " + gr.stage + ",approval:" + current.approval);
if (gr.stage == "waiting_for_approval" && current.approval == "approved") {
gr.approval = "requested";
gr.stage = "request_approved";
gs.log("3.Cascade test: Setting stage to request_approved");
} else if (current.approval == 'rejected') {
gr.approval = "rejected";
gr.stage = "Request Cancelled";
}
}
function getNextStage(reqitem) {
// return the first delivery task
var nextStage = "nothing";
var planID = GlideappDeliveryPlan.resolvePlanID(reqitem);
var gr = new GlideRecord("sc_cat_item_delivery_task");
gr.addQuery("delivery_plan", planID);
gr.orderBy("order");
gr.query();
if(gr.next())
nextStage = gr.name.getDisplayValue();
return nextStage;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 01:00 AM
Hi Ram
I suggest you to try creating a bran new workflow .
A simplified version of the one you have at the moment using just 3 blocks and check if this works.
I've tried on my OOB instance and seems to work.
Have a look.
This is similar to the first part of your workflow right ?
Here's an example
After Approval
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 04:33 AM
Hi Ram
A couple of quick questions.
1- Did you test on the first scenario (delivery plan) or second (workflow) or both ?
2- In case you are using a workflow. Did you check for stages used internal to your req item workflow ? Maybe there is a stage over there that overrides the one in the script.
RObo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 04:44 AM
Hi,
Thank you for starting helping me.
1. I am testing it in the case of workflow, since it's causing the issue in the "workflow".
2. Can you please elaborate, how can check for stages used and what is meant by overriding?? If I approve that request item manually, it's getting approved. But approving the request is not auto-approving this request item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 05:32 AM
Hi Ram
If you check the workflow used by the item in the workflow editor, you should be able to se different blocks right ?
Each block has a stage field.
I suppose that if the stage used by the first block is not empty than the system will use that one instead of the one visible on the script.
Here is an example on the 'service catalog Item request' OOB workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 09:35 PM