How to create form data model using json schema and dynamically populate drop down values for fields country,state,city | Community
Skip to main content
jhansi_lakshmik
Level 2
Jul 10, 2019 7:46 PM UTC
Solved

How to create form data model using json schema and dynamically populate drop down values for fields country,state,city

Hi,

can  anyone suggest how to create a form data model using json in AEM forms 6.5 and how to populate dynamic drop down values for the Adaptive form fields country ,state, city assuming the json contains country,state,city values,is there any way we can achieve this without using servlets.

Thanks in advance,

Jhansi.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Mayank_Gandhi
Mayank_GandhiAccepted solution
Employee
Jul 11, 2019 9:09 AM UTC

RESTful web service can be described using Swagger specifications in JSON or YAML format in a Swagger definition file. To configure RESTful web service in AEM cloud services, ensure that you have either the Swagger file on your filesystem or the URL where the file is hosted.

Here is a simple way to initialize drop down from JSON value: Put this script on form initialise and change the dropdown item name as per your form.

console.log('dropdown init ');

var text = '{"cars":[ "Ford", "BMW", "Fiat" ]}';

var jsonParsed = JSON.parse(text);

console.log(jsonParsed);

var DDL = [];

for (i = 0; i < jsonParsed.cars.length; i++) {

    var idItem = jsonParsed.cars[i];

  console.log(" item idteam"+idItem);

    var nomeAzienda = jsonParsed.cars[i];

  console.log("nomeAzienda"+nomeAzienda);

    DDL.push(idItem + " = " + nomeAzienda);

}

  dropdownlist1562834391516.items = DDL;

  console.log(dropdownlist1562834391516.items);

  console.log("end of init function");

4 replies

Mayank_Gandhi
Mayank_GandhiAccepted solution
Employee
Jul 11, 2019 9:09 AM UTC

RESTful web service can be described using Swagger specifications in JSON or YAML format in a Swagger definition file. To configure RESTful web service in AEM cloud services, ensure that you have either the Swagger file on your filesystem or the URL where the file is hosted.

Here is a simple way to initialize drop down from JSON value: Put this script on form initialise and change the dropdown item name as per your form.

console.log('dropdown init ');

var text = '{"cars":[ "Ford", "BMW", "Fiat" ]}';

var jsonParsed = JSON.parse(text);

console.log(jsonParsed);

var DDL = [];

for (i = 0; i < jsonParsed.cars.length; i++) {

    var idItem = jsonParsed.cars[i];

  console.log(" item idteam"+idItem);

    var nomeAzienda = jsonParsed.cars[i];

  console.log("nomeAzienda"+nomeAzienda);

    DDL.push(idItem + " = " + nomeAzienda);

}

  dropdownlist1562834391516.items = DDL;

  console.log(dropdownlist1562834391516.items);

  console.log("end of init function");

Translate
Mayank_Gandhi
Employee
Jul 10, 2019 8:17 PM UTC

Give me some time I will share the screenshot with you on the approach.

Translate
jhansi_lakshmik
Level 2
Jul 10, 2019 8:07 PM UTC

Hi Mayank Gandhi,

Thanks for the prompt response, we are not connecting to any database , can you suggest how to populate the dynamic drop down list based on the json as a data model

Thanks in advance,

Jhansi.

Translate
Mayank_Gandhi
Employee
Jul 10, 2019 7:50 PM UTC

Hi Jhansi,

Please refer this old thread where I have discussed similar scenario:

Re: AEM 6.3 Forms - How can I populate a dropdownlist from database?

Translate