Tom Philippi · Aug 23, 2017

Testing for not existing item in collection

I have a call in a business process that returns a response which may contain a collection of error message. I use the following code in my response builder to extract the messge value from the first error and map them to a context variable:

Set    context.ErrorMessage   callresponse.result.GetAt(1).errors.GetAt(1).message

This works nicely when an error comes up, however when no error is returned (i.e. the collection is empty) I receive an error: ERROR <Ens>ErrException: <INVALID OREF>zOnResponse2+4^Calarm.UserRegistrationProces.Context.1 -- logged as '-' number - @' Set status=1,context.ErrorMessage=callresponse.result.GetAt(1).errors.GetAt(1).message

Obviously I need to test if the result exists before I transfer it to my context.ErrorMessage. However, I can't find the proper command for that. I tried something like $GET(callresponse.result.GetAt(1).errors.GetAt(1).message), but that doesn't work.

2 0 2 233
Log in or sign up to continue

Have you tried using $IsObject(obj.prop)

to work down a collection of varying number of elements I'd use this kind of loop
in this case it's a double loop

For res=1:1:callresponse.result.Count() {
  For err=1:1:callresponse.result.GetAt(res).Count() {
    Set context.ErrorMessage= callresponse.result.GetAt(res).errors.GetAt(err).message
    - - - -

This is the paranoic version!
If you trust ENSEMBLE you may skip the check for $IsObject()