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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Prefilling form with JSON

christofhed3545
Level 2
Level 2

Hi

Currently i'm working on a case to prefill a form. With XML it works fine but with JSON it doesn't seems to work.

As reference I used this page.

Adobe Experience Manager Help | Prefill adaptive form fields

It seems that something is missing for prefilling a form with json.

Kind regards,

Christofhe

1 Accepted Solution
James_R_Green
Correct answer by
Level 7
Level 7

Hi christofhed35451717,

It works pretty much the same as the XML example you have working.  You use the two functions:

guideBridge.getGuideState

guideBridge.restoreGuideState

To test this out, when previewing in inspector console do this:

window.guideBridge.getGuideState({

     success : function (guideResultObj) {

         jsonData = guideResultObj.data;

         console.log(JSON.stringify(jsonData,null,2));

     },

     error : function (guideResultObj) {

         // log error

     },reducedJSON:true

});

Copy the string produced and restore:

var jsonData = "guideState": {

  "guideDom": {

etc"; //output from getGuideState

guideBridge.restoreGuideState({

  guideState : jsonData.guideState,

  error : function (guideResultObject) {

  console.log('failed', guideResultObject);

  }

  });

Thanks,

James

View solution in original post

0 Replies
jagjeetthukral
Level 3
Level 3

Hi christofhed35451717​,

The instructions here work as is. I guess we will need some more information to help you debug. For starters you can compare the json you are populating your form with to the json created when you save the form.

You can get the json on form save easily via network panel.

While comparing you can have it either with or without afdata wrapper.

Cheers,Jagjeet Singh

AEM Forms Blog

christofhed3545
Level 2
Level 2

Hi jagjeetthukral

This is the format of my json

{

   "afData": {

      "afUnboundData": {

         "data": {

            "textbox": "testing"

         }

      },

      "afBoundData": {

         "data": null

      }

   }

}

Probably this is not right?

Kind reagrds,

Christofhe

jagjeetthukral
Level 3
Level 3

A few questions to identify the issue:

1. Is your forms Json Model Based?

2. Is the name of field which your are trying to populate "textbox"

If answer to both the question is yes, then please try below JSON

{

   "afData": {

      "afUnboundData": {

         "data": {

            "textbox": "testing"

         }

      }

}

Hope this helps !!!

Cheers,

Jagjeet Singh

AEM Forms Blog

James_R_Green
Correct answer by
Level 7
Level 7

Hi christofhed35451717,

It works pretty much the same as the XML example you have working.  You use the two functions:

guideBridge.getGuideState

guideBridge.restoreGuideState

To test this out, when previewing in inspector console do this:

window.guideBridge.getGuideState({

     success : function (guideResultObj) {

         jsonData = guideResultObj.data;

         console.log(JSON.stringify(jsonData,null,2));

     },

     error : function (guideResultObj) {

         // log error

     },reducedJSON:true

});

Copy the string produced and restore:

var jsonData = "guideState": {

  "guideDom": {

etc"; //output from getGuideState

guideBridge.restoreGuideState({

  guideState : jsonData.guideState,

  error : function (guideResultObject) {

  console.log('failed', guideResultObject);

  }

  });

Thanks,

James

View solution in original post

ashi_ADx
Level 1
Level 1
Can we prefill Attachment through json in aem forms by writing java prfill class?
GirishBedekar
Level 9
Level 9

You want to prefill the attachment when it is added to the form?