- 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-09-2016 12:42 AM
I also exported workflow from working instance to this not working instance. Even then the issue exists. So, I am expecting issue is not with work flow. It might be with some thing else?
- 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-09-2016 01:03 AM
Hi,
If i approve Request item, then it's going to Approval state. There is no problem with that. But if i approve Request, RequestItem workflow is not going to "Approved" state.
So, Can you check your case with by approving the request instead of request item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-09-2016 02:09 AM
Thanks Robo.
This technique helped me in identifying the issue. Built this sample workflow, then it's working fine. Slowly turned into actual workflow. Then understood the issue. It was with "approver" permissions. With a wrong role, we are approving.