How can I iterate through it?
Specifically, I would like to extract the “childDevicesIds” and “email” values.
The code I currently have for printing this is as follows:
action onload() {
integer reqId := com.apama.cumulocity.Util.generateReqId();
com.apama.cumulocity.FindManagedObject request :=
new com.apama.cumulocity.FindManagedObject;
request.reqId := reqId;
// Optionally provide the 'id' of the managed object
request.deviceId := "1523844618";
// Filter based on fragmentType
request.params.add("fragmentType", "c8y_IsDevice");
// Subscribe to com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL to
// listen for responses
monitor.subscribe(com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
// Listen for responses based on reqId
on all com.apama.cumulocity.FindManagedObjectResponse(reqId=reqId) as response
// Avoid listener leaks by terminating the listener on completion of the request
and not com.apama.cumulocity.FindManagedObjectResponseAck(reqId=reqId)
{
log "Received ManagedObject " + response.managedObject.toString();
}
// Listen for com.apama.cumulocity.FindManagedObjectResponseAck,
// this indicates that all responses have been received
on com.apama.cumulocity.FindManagedObjectResponseAck(reqId=reqId)
as requestCompleted
{
log "Received all ManagedObject(s) for request "
+ requestCompleted.reqId.toString() at INFO;
// Request is completed and we can unsubscribe from this channel
monitor.unsubscribe(com.apama.cumulocity.FindManagedObjectResponse.SUBSCRIBE_CHANNEL);
}
// Send request to find available managed objects
send request to com.apama.cumulocity.FindManagedObject.SEND_CHANNEL;
}
This is is a dictionary and you have multiple options to extract from it (assuming “email” is a top level element in params which is a bit hard to read from your screenshot):
// Option 1: do only if you KNOW that email exists, will crash your EPL App if it does not
sequence<any> emails := response.managedObject.params["email"];
// Option 2: safe; use if you only need to do something if the field exists
if(response.managedObject.params,hasKey("email") {
sequence<any> emails := response.managedObject.params["email"];
}
// Option 3: safe; do if you can work with a default value
sequence<any> emails := response.managedObject.params.getOrDefault("email")
// Option 4: safe; do if you can define your own default value
sequence<any> emails := response.managedObject.params.getOr("email", new sequence<any>)
Important: if these IDs are supposed to be Cumulocity device ids you should change their type to string. While the device IDs are numerical they are stored as strings and there is no guarantee that they can be represented as integers.
Error on line 414 in action getMember in event com.apama.util.AnyExtractor: ParseException - Unable to parse "childDevicesIds" as integer - /opt/softwareag/Apama/monitors/AnyExtractor.mon
What should I do?
Same things happens if I try with string, sequence.
Please have a read of the documentation I shared with that it should be easier for you than for me to do the right navigation as you understand your data model better than I. It looks like there is an additional array in your data model that I missed. This should work: