Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Pre-populate form fields

Avatar

Avatar
Validate 1
Level 2
alexandrad27705
Level 2

Likes

2 likes

Total Posts

19 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 2
alexandrad27705
Level 2

Likes

2 likes

Total Posts

19 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
alexandrad27705
Level 2

29-03-2016

Hi, 

I have an adaptive form which has unbound and bound fields because it it partially based on a XDP form model. 

I now need to pre-fill some of the fields with data from the currently logged in user. 

I found Adobe example files and took the following route: 

  1. Created a prefill.jsp 
  2. Include the prefill.jsp in the head.jsp of the form
  3. prefill.jsp gets the user data and creates the xml:

<%
    final boolean isAnonymous = UserPropertiesUtil.isAnonymous(slingRequest);
    boolean isDisabled = WCMMode.fromRequest(request).equals(WCMMode.DISABLED);
    if(!isAnonymous && isDisabled && slingRequest.getParameter("dataRef")== null
            && slingRequest.getAttribute("data")==null){

        UserProperties userProperties = slingRequest.adaptTo(UserProperties.class);
        String givenName = userProperties.getProperty("givenName");
        String dataXML="<afData>" +
                            "<afBoundData>" +
                                "<dataRoot>" +
                                    "<General_firstName>"+ StringUtils.trimToEmpty(userProperties.getProperty("givenName")) + "<General_firstName>" +
                                    "</dataRoot>" +
                            "</afBoundData>" +
                        "</afData>";
        slingRequest.setAttribute("data", dataXML);
    }
%>

In the above snippet, "<General_firstName>" is the element name of the form field. 

The jsp is included and has no errors, but the field is not pre-filled. Does the XML need a different structure? The above field was dragged from the content finder (the loaded XDP) but I also have unbound fields. 

Any help is greatly appreciated. 

Please don't point me to the documentation -  https://helpx.adobe.com/aem-forms/6-1/prepopulate-adaptive-form-fields.html - since it did not help me 😞

Thanks, Alex

View Entire Topic

Avatar

Avatar
Validate 10
Level 2
doeringa
Level 2

Likes

3 likes

Total Posts

54 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
doeringa
Level 2

Likes

3 likes

Total Posts

54 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Boost 3
Boost 1
View profile
doeringa
Level 2

31-03-2016

Solved it 🙂