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

Resetting the guidestate of the form using a response from a webservice.

Avatar

Level 4

Hi all,

I am trying to create a function using GuideBridge API to populate the fields in an adaptive form from the response of an API, which gives me a key value pair where, the key matches the element name of the form field. I am trying to write a common function where multiple teams can use it without modifying the function. Any inputs would be appreciated.

Thanks,

Deepak

1 Accepted Solution

Avatar

Correct answer by
Level 10

Yes, you can restore the state with an XML source as well.

guideBridge.getData({
     success : function (guideResultObj) {
         var data = guideResultObj.data;
         //post the data to a server that saves it at say http://abc.com/my/data.xml
         //or http://abc.com/my/data.json
     },
     error : function (guideResultObj) {
         // log the errors
     }
});

// after some time or on click of a button or reloading the page
guideBridge.restoreGuideState({
     dataRef : "http://abc.com/my/data.xml",
     error : function (guideResultObject) {
         // log the errors
     }
})

View solution in original post

3 Replies

Avatar

Level 10

The title and the summary talk about two different scenarios, if we go with the summary then you need a few essential things:

1. All the forms need to follow some kind of naming convention for element Names.

2. All the elements you try to set must exist in the form.

3. Call the service to load the data and on success callback do the set value of the fields using the guideBridge.resolveNode("elementName").value

If we go with the title:

Adaptive Form can be restored in three ways

  • by passing the JSON data obtained from GuideBridge#getGuideState. This can be done by setting data property
  • by passing a URL pointing to a resource that returns XML that should be used. This can be done by setting dataRefproperty. The XML can be obtained by calling the getDataXML API.
  • by passing a URL point to a resource that returns JSON data obtained from GuideBridge#getGuideState. This can be done by setting guideStatePathRef property

Example:

var jsonData

guideBridge.getGuideState({

     success : function (guideResultObj) {

         jsonData = guideResultObj.data;

     },

     error : function (guideResultObj) {

      // log error

     }

});

// after some time or on click of a button or reloading the page

guideBridge.restoreGuideState({

     data : jsonData

     error : function (guideResultObject) {

     // log the errors

     }

})

Thanks,

Mayank

Avatar

Level 4

Can the dataref be set to an xml source and populate the fields without reloading the form?

Avatar

Correct answer by
Level 10

Yes, you can restore the state with an XML source as well.

guideBridge.getData({
     success : function (guideResultObj) {
         var data = guideResultObj.data;
         //post the data to a server that saves it at say http://abc.com/my/data.xml
         //or http://abc.com/my/data.json
     },
     error : function (guideResultObj) {
         // log the errors
     }
});

// after some time or on click of a button or reloading the page
guideBridge.restoreGuideState({
     dataRef : "http://abc.com/my/data.xml",
     error : function (guideResultObject) {
         // log the errors
     }
})