PrePopulate Adaptive Forms using query parameters

Last update: 2023-11-30
  • Created for:
  • Experienced

One of our customers had the requirement to populate adaptive form using the query parameters. For example in the following url the FirstName and LastName fields in the adaptive form are set to John and Doe respectively

To accomplish this use case a new adaptive form template was created and associated with a page component. In this page component we have a jsp to get hold of the query parameters and create an xml structure that can be used to populate the adaptive form.

The details on creating a new Adaptive Form template and page component are explained in this video.

The following is the code that was used in the jsp page

java.util.Enumeration enumeration = request.getParameterNames();
String dataXml = "<afData><afUnboundData><data>";
while (enumeration.hasMoreElements())
   String parameterName = (String) enumeration.nextElement();
   dataXml = dataXml + "<" + parameterName + ">" + request.getParameter(parameterName) + "</" + parameterName + ">";


dataXml = dataXml + "</data></afUnboundData></afData>";
//System.out.println("The data xml is "+dataXml);
slingRequest.setAttribute("data", dataXml);

If your form is using schema the structure of your xml will be different and you will have to build the xml accordingly.

Deploy the assets on your system

On this page