How to populate the list of available values of a select widget

ismail.lagouilly_1386495's picture
ismail.lagouilly_1386495
Blog Categories: 

Question:
How can we populate a select widget based on an External API, Javascript, or a Json variable.

Answer:
To populate the list of available values of a select widget using an External API for example, you can do the following:

1) Create an External API variable, example : externalAPIVaribale
Value : ../API/identity/user?p=0&c=10&o=lastname%20ASC&s=will&f=enabled%3dtrue

This API returns :

[
{
"firstname": "William",
"icon": "icons/default/icon_user.png",
"creation_date": "2019-08-06 11:14:40.084",
"userName": "william.jobs",
"title": "Mr",
"created_by_user_id": "-1",
"enabled": "true",
"lastname": "Jobs",
"last_connection": "",
"password": "",
"manager_id": "0",
"id": "1",
"job_title": "Chief Executive Officer",
"last_update_date": "2019-08-06 11:14:40.084"
},
{
"firstname": "Zachary",
"icon": "icons/default/icon_user.png",
"creation_date": "2019-08-06 11:14:40.194",
"userName": "zachary.williamson",
"title": "Mr",
"created_by_user_id": "-1",
"enabled": "true",
"lastname": "Williamson",
"last_connection": "",
"password": "",
"manager_id": "1",
"id": "5",
"job_title": "Chief Financial Officer",
"last_update_date": "2019-08-06 11:14:40.194"
}
]

2) Select the variable externalAPIVariable in "Available values" property
3) Select the attribute you want to display (here we will choose job_title) in "Displayed key" property
4) Select the attribute you want to return (here we will choose id) in "Returned key" property
5) Finally, select the variable where you want to store the final result in "Value" property.

PS: As you might have noticed, using a Javascript, Json or External API Variable all are used following the same procedure. The only condition is that data has to be in a well-formatted Json array, or just string values separated by commas (Option1, Option2 etc).

You find attached to this article an example of a form using a select widget (using the 3 examples) on Bonita 7.8.4:
https://drive.google.com/file/d/1uZ6Gw5SlvqeQBcA9L9fdjJAMgTWY0Pfl/view?u...

Hope this article helps.

Notifications