Using %request.Data in production
I am trying to pass %request.Data
from my rest dispatch class to a production so that I can use it in by business operation. I have created a message that has a property:
Property urlParameters As %String [multidimensional];
ObjectScriptObjectScript
to get the data to the production. I am new to intersystems and multidimensional arrays/globals
dispatch class:
Kill parameters
Merge parameters = %request.Data
Set genericRequest = ##class(Core.API.V1.Msg.GenericRequest).%New()
Set genericRequest.urlParameters = parameters
ObjectScriptObjectScript
business operation:
Access data from the multidimensional array that is being passed in the property genericRequest.urlParameters
.
Any suggestions are greatly appreciated.
Thanks
Dan
Product version: IRIS 2022.1
Use Merge in your Business Service:
Set genericRequest = ##class(Core.API.V1.Msg.GenericRequest).%New() Merge genericRequest.urlParameters = %request.Data
And in BusinessOperation you can use this syntax:
genericRequest.urlParameters("key")
I was not able to get the code to work.
Kill parameters
Merge parameters = %request.Data
Set genericRequest = ##class(Core.API.V1.Msg.GenericRequest).%New()
Set genericRequest.urlParameters = parameters
I was not able to get the code to work when my class had property
Property urlParameters As %String [multidimensional];
I was able to get it to work with the following.
Property urlParameters As %Library.ArrayOfDataTypes; //property in generic request class
In Dispatch:
Set genericRequest.urlParameters = ##class(%Library.ArrayOfDataTypes).%New()
Set propName = $Order(%request.Data(""))
While (propName '= "") {
Set param = %request.Data(propName, 1)
do genericRequest.urlParameters.SetAt(propName, param)
Set propName = $Order(%request.Data(propName))
}
A multidimensional property is an array. You should use the "Merge" command to set it, instead of the "Set" command, like in Eduard's example.