I was putting together a simple demo earlier with a DDS button, and could not get data to propagate back from my service without wrapping it in a JSON object with a key. A simple array or even a string with a single character was not being populated into the field I specified (with the Key option left blank). However, when I returned a JSON object with a key from the service, I was able to specify that key in the DDS button settings and the data populated perfectly in the form. I was under the impression that a key was not mandatory if the data didn't require it.
To be clear:
The original service code essentially only executed
And the DDS button Response Field Mapping was set to a blank Key with the proper data field. This did not succeed in populating the data field.
When I changed the service to return
and added the key to the mapping, it worked perfectly.
So my question is, am I missing a piece of information or do I always need to specify a key in order to map my response properly?
The Dynamic Data Button component is set up to support the common case where your service returns a JSON object. If you want to return a simple value then you can use a regular button with a click rule script like:
data.myResponseField = response;
Yes, in my opinion you should always specify key value pairs in the JSON response from a groovy service.