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

deepakt84913413

12-02-2019

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

Accepted Solutions (1)

Accepted Solutions (1)

Mayank_Gandhi

Employee

15-02-2019

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
     }
})

Answers (2)

Answers (2)

Mayank_Gandhi

Employee

12-02-2019

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