Ens.BusinessProcessBPL: context variable is being cleared after a synchronous call to a Business Operation
I have a Business Process where I am receiving a JSON payload in the "Body" property of the my request class. I defined a context variable as an object of a class that represents the JSON schema I expect to receive and load the JSON payload in that context variable.
XData BPL [ XMLNamespace = "http://www.intersystems.com/bpl" ]
<process language='objectscript' request='mapi.core.msg.rq.RestBusinessServiceRequest' response='mapi.core.msg.rp.RestBusinessServiceResponse' height='2000' width='2000' >
<property name='cm' type='mapi.exchange.msg.Communication' instantiate='1'/>
<sequence xend='200' yend='450' >
<code name='Map request payload' xpos='200' ypos='250' >
<annotation><![CDATA[Map request body to mapi.exchange.msg.communication]]></annotation>
s status = context.cm.%JSONImport(cmReq)
My mapi.exchange.msg.communication class has a property called Recipients which is a list.
I need to loop through the recipients and invoke a Business Operation "Send Email" for each recipient. Here is the example of syntax I use,
<assign property="callrequest" value="context.cm.Recipient.GetAt(key)" action="set" />
<response type='mapi.exchange.msg.CommonPostResponse' >
After the call to BO, it seems like my conext.cm variable gets cleared and <foreach> fails with <INVALID OREF> when trying to do .Next() on my cm.Recipient property. Any ideas on what I am doing wrong here?
Note: if I make an asynchronous call to "Send Email" then context variable is not cleared and my process works but I need the call to "Send Email" to be synchronous.