// Load product volumes from DM to Planning HttpResponse jsonResponse = operation.application.getConnection("DM").post() .body(json(["jobType":"DATARULE", "jobName":"ProductVolumes", "startPeriod":"Jan-17", "endPeriod":"Dec-17", "importMode":"REPLACE", "exportMode":"STORE_DATA", "fileName":"inbox/ProductVolumes.csv"])) .asString(); boolean pushDataToPlanning = awaitCompletion(jsonResponse, "DM", "Push Product Volumes to Planning") if(pushDataToPlanning) { // Capture the periods and products whose volumes were loaded Set editedMembers = [] operation.grid.dataCellIterator().each { DataCell cell -> editedMembers << cell.periodName << cell.getMemberName("Product", MemberNameType.ESSBASE_NAME) } } // Wait for DM job to be completed def awaitCompletion(HttpResponse jsonResponse, String connectionName, String operation) { final int IN_PROGRESS = -1 if (!(200..299).contains(jsonResponse.status)) throwVetoException("Error occured: $jsonResponse.statusText") // Parse the JSON response to get the status of the operation. Keep polling the DM server until the operation completes. ReadContext ctx = JsonPath.parse(jsonResponse.body) int status = ctx.read('$.status') for(long delay = 50; status == IN_PROGRESS; delay = Math.min(1000, delay * 2)) { sleep(delay) status = getJobStatus(connectionName, (String)ctx.read('$.jobId')) } println("$operation ${status == 0 ? "successful" : "failed"}.\n") return status == 0 } // Poll the DM server to get the job status int getJobStatus(String connectionName, String jobId) { HttpResponse pingResponse = operation.application.getConnection(connectionName).get("/" + jobId).asString() return JsonPath.parse(pingResponse.body).read('$.status') }