Revert in Epl

How to use revert and fromDate in find measurement query in epl apps?
I want to get the latest measurement for the current day of particular type.

Hello Vaibhavi,
Below find the sample Code snippet

FindMeasurement request := new FindMeasurement;
request.reqId := reqId;
request.params.add("fromDate", (currentTime - 86400.0).toString());
request.params.add("toDate", currentTime.toString());
request.params.add("revert","false");

Thanks,
Divya K

1 Like

I am not sure why, but this snippet isn’t working.

@vaibhavi_ghumare ,
Can you please mention if you getting any errors or what is the behavior,
In case of executing range queries between an upper and lower boundary, for example, querying using dateFromdateTo , the oldest registered measurements are returned first. It is possible to change the order using the query parameter revert=true .
https://cumulocity.com/api/core/10.16.0/#operation/getMeasurementCollectionResource
Below is the full code snippet which is working


monitor MySampleMonitor {
	action onload() {
		monitor.subscribe(FindMeasurementResponse.SUBSCRIBE_CHANNEL);
			integer reqId := integer.getUnique();
				FindMeasurement request := new FindMeasurement;
				request.reqId := reqId;
				request.params.add("fromDate", "1701864437");//date is in epoch format
				request.params.add("toDate", "1701950837");
				request.params.add("revert","true");		
				on all FindMeasurementResponse(reqId=reqId) as resp
				and not FindMeasurementResponseAck(reqId=reqId) 
				{
					log "Received measurements " + resp.toString() at INFO;
				 	
				}
						
				on FindMeasurementResponseAck(reqId=reqId) as requestCompleted
				{
					log "Received all measurements(s) for request " + requestCompleted.reqId.toString() at INFO;
					
				}
				send request to FindMeasurement.SEND_CHANNEL;
	}
	
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.