Different JSON structure in form
Hi,
I'm new to bonita and JSON, I read a lot of posts on the forum but found no relevant infos on my problem.
I'm using a REST GET connector to fetch some infos from a webservice.
I have a process variable of HashMap type to witch I affect the result of the REST GET with "bodyAsObject".
If I test the webservice (with postman chrome extension), the JSON looks like :
{
"organizations": [
{
"url": "https://xxx.zendesk.com/api/v2/organizations/7712313309.json",
"id": 7712313309,
"name": "xxx",
"shared_tickets": true,
"shared_comments": false,
"external_id": null,
"created_at": "2017-01-28T09:40:25Z",
"updated_at": "2017-02-20T09:14:34Z",
"domain_names": [
"xxx.ch"
],
"details": "",
"notes": "",
"group_id": null,
"tags": [],
"organization_fields": {}
}
],
"next_page": null,
"previous_page": null,
"count": 1
}
But if I display the process variable value in a text widget (for debug proposes), I have the following JSON :
{
"case_id": "57019",
"name": "zendeskTicketList",
"description": "",
"type": "java.util.HashMap",
"value": "{next_page=null, organizations=[{url=https://xxx.zendesk.com/api/v2/organizations/7712313309.json, id=7712313309, name=xxx, shared_tickets=true, shared_comments=false, external_id=null, created_at=2017-01-28T09:40:25Z, updated_at=2017-02-20T09:14:34Z, domain_names=[xxx.ch], details=, notes=, group_id=null, tags=[], organization_fields={}}], count=1, previous_page=null}"
}
The part I need is considered like a string.
Any ideas ?
Thanks in advance for your help
Here is a solution that is a slight adjustment to what you already tried:
- Define a new Business Object that will be used to store useful information that you get from the REST API call.
- Add a business variable to your process definition using the previously created new business object. Leave the default value empty.
- Use the REST connector to perform the REST API call.
- In the last page of the connector configuration wizard, use the provided variable
bodyAsObject
to create a new instance of a Business Object (using a Groovy Script) and map the script execution result to your business variable. - In your form, add a variable (e.g. named "myFormVar") of type "External API" and set the URL to call to:
../{{context.myVar_ref.link}}
(replacemyVar
with the name of your business variable). - Bind the form variable to a widget to display the value: myFormVar.myAttributeName
The other option that I would recommend is to directly call the REST API from the form. Simply add a variable of type "External API" and set the URL value to the REST API URL. Limitation of this solution is that the REST API must allow cross domain call.
I create an example that illustrate both solution with a public web service: https://www.dropbox.com/s/i0m2go43mjhcnqh/DemoRESTAPIFormDiagram-1.0.bos...
Comments
Hello,
Thanks a lot for you answer.
I will test asap and will let you know.
See you