Groovy Sample – UpdateDimension.groovy for Profitability and Cost Management

Prerequisites: json.jar

Common functions: See Appendix C: Common Helper Functions for Groovy.

def updateDimensions() {
        
        JSONObject json = new JSONObject();
        json.put("dataFileName", "Accounts.txt");
        
        String urlString = serverUrl + "/epm/rest/"+ apiVersion + "/fileApplications/"+ appName + "/updateDimension";
        def url;
        
        try {
                url = new URL(urlString)
        } catch (MalformedURLException e) {
                println "Malformed URL. Please pass valid URL"
                System.exit(0);
        }
        
        String response = executeRequest(url, "POST", json.toString(), "application/json");
        JSONObject jsonObj = new JSONObject(response);
        int resStatus = jsonObj.getInt("status");
        
        if(resStatus == 0) {
            println "Dimensions updated successfully"
        } else {
            println "Dimensions update failed"
        } 
    }