Using approvals basically allows you to monitor and manage your workflow within the specified process. Approvals help you manage the corporate planning process and gives you chance to formalise approval authorities with using validation rules.

In today’s topic, we are going to process approvals with using Groovy scripts which are integrated with Rest API. If you encounter any problem for connecting to Rest API please read “Rest – API Export Data Slices” before you continue.

Let’s assume that you have got 1200GBP revenue on West Division 1 for 2020 like below and you would like to promote the value to the upper level so that it can be reviewed and approved. 

Before jumping in the details of script, you need to ensure that there is a connection defined in your epm cloud application. This will allow you make Rest API requests from your groovy enabled business rules.

Please visit my earlier blog “Groovy – Read from Virtual Grids” to find detailed information about creating an object of Cube and using the methods of gridBuilder. You may need to read details from the cube and decide next action on the approval process. Why not reject the approval unit if submitted revenue is not greater than last years actual number ?

Let’s first get available actions from the approval unit using /availableactions restAPI. A simple body where you need to state pmMember is required to make this API work. 1017 in the following example is nothing but the ID of West – Div I in my application.

def body = 'pmMember=1017'
HttpResponse<String> jsonResponseavailableactions = operation.application.getConnection("MyConnection").post("/availableactions").body(body).asString(); 
println(jsonResponseavailableactions.body)           

Following JSON Body returns as a response from /availableactions restAPI. You can simply check the action you want to perform against a particular approval unit is indeed a valid action. For instance, you may want to promote an approval unit but if process has already progressed and unit is approved. Promote would not be even an action in the available list of actions.

Let’s suppose you have promote in available action list and you have checked 1200 is a valid number to send for further approvals. You could simply read with a virtual grid from prior year’s actual scenario and see it was 1000 for the same department. %20 increase is not bad, so you don’t block the promote attempt that user is sending. It is time to use /actions RestAPI to change approval unit status.

def body = 'actionID=6&pmMember=1017&comments="Promoting Sales Data"
HttpResponse<String> jsonResponse = operation.application.getConnection("MyConnection").post("/planningunits/"Scenario"::"Version"/actions").body(body).asString();

You can simply see approval units and find how it is updated from groovy side. This mechanism allows you to seamlessly integrate overall epm processes and approvals processes together. You can run business rules checking approval units status behind forms or give users controls with action menus to move around in their approval process that will be tightly aligned with overall epm process.

LEAVE A REPLY

Please enter your comment!
Please enter your name here