1
0
-1

Hi,

I'm investigating use of the above function in a Composer form and need some more guidance.

How do I access the returned data?

Is it provided in the onSuccessNotify function? as an object? named?

Should I write my onSuccessNotify function as:

function onSuccessNotify(data) { do something with data object here etc. }


To provide the inputData I have some options: retrieve a value from a cookie, or get data from a form field.

Can I access cookies in the 'click' script for the 'Next' button?

If I need to get data from a form field I also need to work out how to write data to the field during page load, so that the data is available when the 'Next' button is clicked and the above function is executed.


The online documentation for sfc | JsDoc Reference does not have an example, and I cant find any more information in the Composer Product Dcoumentation.


Any help would be appreciated.


Thanks

Mark

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1
      The first param is a standard composer event object whose evtData property holds a json 
      object that looks like

      {

      "resultData": <This is your returned Json data from the Dynamic Data call>

      "serviceName": <This is the TM service name you supplied in the call>

      "operationName": "dynamicData"

      }

      The 2nd param is the sourceNode you supplied in the function call

      So write something like this
      function onSuccessNotify(evt,sourceNode) {

          var returnedData = evt.evtData.resultData

      ....

      }

      Note: I'm also just going by the source code inspection so I might be slightly off in the details ie. I didn't double check by checking at run time as I don't have a dynamic data call handy.


      The input data just needs to be a json object in string form how you build it is entirely up to you

      1. Mark Murray

        Hi David,

        thanks for the feedback.

        I'll give that a try and let you know. I won't get to it until later in the week, as I have other commitments, but I'll provide some feedback.


        Thanks

        Mark

      2. Mark Murray

        Hi David,

        I've made some progress and implemented the dynamic data call based on your comments. However, when I invoke the service I get an error - 400: Bad Request.

        Using dev tools shows that the response is: { "errorMessage": "Service name not set" }.

        The code I'm using is as follows, so not sure what causes the error, as service name is given as the second parameter, and that matches the service name in TM.

        // Dynamic Data call to TMx
        
        var getCookie = function (cname) {
            var name = cname + "=";
            var decodedCookie = decodeURIComponent(document.cookie);
            var cList = decodedCookie.split(';');
            for(var i = 0; i <cList.length; i++) {
                var c = cList[i];
                while (c.charAt(0) == ' ') {
                    c = c.substring(1);
                }
                if (c.indexOf(name) == 0) {
                    return c.substring(name.length, c.length);
                }
            }
            return "";
        }
        
        var onSuccessNotify = function (evt, {LetsGetStarted_1}) {
            console.log("onSuccessNotify()");
            var data = evt.evtData.resultData;
            
            console.log("data = " + data);
        }
        
        var onFailureNotify = function (err) {
            console.log("err = " + err.toString());
        }
        
        var session_id = getCookie('sid');
        console.log("session_id: " + session_id);
        
        var inputData = "{'session_id': session_id}"
        
        
        sfc.getDynamicDataFromJson({LetsGetStarted_1}, "TMx Session Query", inputData, onSuccessNotify, onFailureNotify, true);
        
        
        


        Is this an error in my code, or an error in the sfc call?

        Any ideas?


        Thanks

        Mark

      3. Mark Murray

        Hi David,

        thanks for the comments.

        In the end I used sfc.getDynamicData() and used the form nodes, and managed to get it working.


        Thanks

        Mark

      CommentAdd your comment...