How to invoke BusinessProcess from Extends (Ens.BusinessService, %CSP.REST) class
Hi Friends ,
I have a requirement to expose REST endpoint to consume JSON payload and process it with BusinessProcess invocation.
Here is the code
Set instance = ..%New()
Set tSc = instance.SendRequestSync("CIESendInviteProcess",cieinviteReqObj,.pResponse)
end up with run time exception, plz help me to resolve it.
Thanks,
Prashanth
Product version: IRIS 2023.3
Hi Prashanth,
I had a similar requirement once. The following is how I managed it:
First, I setup a method in a CSP dispatch class, which respond to a REST endpoint, to invoke a Business Service in the current namespace working production:
ClassMethod SomeRestEndpointCallback(body As %DynamicArray) As %DynamicObject { $$$TOE(st, ##class(Ens.Director).CreateBusinessService("BusinessServiceName", .service)) $$$ThrowOnError(service.ProcessInput(body, .output)) Return output }
Then, I created a adapterless Business Service (https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...) in order to don't pooling for data but just wait for an external trigger instead:
Class some.package.AdapterlessBS Extends Ens.BusinessService { /// Configuration item(s) to which to send file stream messages Property TargetConfigNames As Ens.DataType.ConfigName(MAXLEN = 1000); Parameter SETTINGS = "TargetConfigNames:Basic:selector?multiSelect=1&context={Ens.ContextSearch/ProductionItems?targets=1&productionName=@productionId}"; Method OnProcessInput(request As %RegisteredObject, Output response As %RegisteredObject) As %Status { Set tSC = $$$OK Try { // Could be any message... adapter to your needs Set tMsg = ##class(Ens.StringResponse).%New() Set tMsg.StringValue = "some value" // Send the message to the targets Set targets = $LFS(..TargetConfigNames) For i=1:1:$LL(targets) { Set target = $LG(targets, i) // can be sync or async... it's up to you decide //Set tSC = ..SendRequestSync(target, tMsg) Set tSC = ..SendRequestAsync(target, tMsg) Quit:$$$ISERR(tSC) } } Catch (ex) { Set tSC = ex.AsStatus() } Quit tSC }
Now, you can add this Business Service to a interoperability production and set the desired Business Process as its target. So, when your REST endpoint is accessed, it will call the BS and then the BP.
HTH,
José
Hi Prasanth,
Here is the link https://community.intersystems.com/post/implementing-basic-auth-rest-api use it for your requirement.