I'm trying to implement a dynamic data service into my practice Maestro form, and it's not working out too well. I've created a dummy service that just returns some hardcoded JSON, and attempted to call it from a calculation rule on a text field. The script from that rule:
When I preview the form or render it from TM, it throws this error in an alert box infinite times:
"HTTP POST /maguire/servlet/FormDynamicDataServletService name not set"
The console then infinitely spits out error messages reading:
I really have no idea what is happening with this. The name of the service is correct, I double checked. Can anyone provide some insight as to what is causing this behavior?
There are a number of things wrong with this approach, which I'll go through below. The best way to move forward would be to start a new form, drop in a standard Dynamic Data Button, set it's service name in the properties panel, along with any field mappings for parameters and return results, and use that to test your service. From there, if you wish to build custom code, you can look at the pre-made click rule on the Dynamic Data button and go from there.
Here are some of your problems:
First, don't call a Dynamic Data Service in a calculation rule. Calculation rules can run any number of times, which is how the calculated field constantly stays in sync with its dependencies. In your case, it will reissue the call indefinitely, which is why you're seeing repeated errors. A Dynamic Data call should be only be done on an event-type rule, such as click, change, blur and so on, that happen at distinct moments. It's ok in certain situations to use one in a validation rule as well (Maestro validation is asynchronous to allow for this) but bear in mind that validation can also occur multiple times - page change, submit, other fields changing - so make sure your call is quick and idempotent if you wish to use it that way.
Second, you are sending an array in the parameters part of the DynamicData.call signature. It takes an object, with property keys matching your service parameter names.
Third, Dynamic Data calls are asynchronous. You are treating it as a synchronous call. Nothing is synchronous in web API calls (languages like Java can fool you into thinking so, due to thread-blocking APIs). The return value of DynamicData.call() is a promise, which you can handle using the standard Promise API - i.e. call it's .then() function passing a response handler. Again, you'll see an example of this in the standard Dynamic Data button.
Wow, I figured I was doing at least one thing wrong but not three. Thank you for your detailed answer, since there isn't much documentation on best practices at the moment it's really valuable to have these questions answered.
I've solved my problem except for one issue - an error occurring when I click the DDS button. An alert box is displayed that reads:
HTTP POST /maguire/servlet/FormDynamicDataServlet
Parameter 'sfmRequestKey' not set
I've spoken with Rak and he says this looks like a bug, since that parameter is supposed to be set automatically. In the meantime I'm using Test Mode as a workaround, and in that mode everything works perfectly. What does this situation look like to you?
Brian, are you trying to execute the dynamic data call in preview mode? If so, you have to use test mode as this article suggests: https://support.avoka.com/kb/x/CYDOAQ - of course you can always publish the form and then run the dynamic data calls from the published form.