Groovy Sample – ExportQueryResult.groovy for Profitability and Cost Management

Prerequisites: json.jar

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

def exportQueryResult() {
        String queryName = "Profitability - Product";
        String fileName = appName +"_"+ queryName + "_Query_Result";
            
        JSONObject json = new JSONObject();
        json.put("queryName", queryName);
        json.put("fileName", fileName);
        json.put("exportOnlyLevel0Flg", false);
        
        String urlString = serverUrl + "/epm/rest/"+ apiVersion + "/applications/" + appName + "/jobs/exportQueryResultsJob";
                
        def url;   
        
         try {
                 url = new URL(urlString)
         } catch (MalformedURLException e) {
                 println "Malformed URL. Please pass valid URL"
                 System.exit(0);
         }        
        executeJob(url, "POST", json.toString());
}