1
0
-1

I'd like to post the current form XML from a Maestro form to a TM dynamic data service. I'm using a page load rule.

var params = {};
params.xml = Form.getDataXml(false, true);
DynamicData.call("Service name", params).then(function (response) {    
	// do stuff with response
    Form.fireRule("onSuccess", item, data, response);
    
}).catch(function (err) {
    Form.fireRule("onFailure", item, data, err);
});

The problem is that the param with the XML gets silently emptied before it gets to TM. If I send a simple String, it gets through, so perhaps its to do with encoding? I tried encodeURI(), encodeURIComponent() etc... I can see that Form.backgroundSave() serialises the XML with JXON before sending. How do I do it from a rule?

  1. Trevor Ward

    I was going to ask the same question.  Looking forward to the answer.

CommentAdd your comment...

3 answers

  1.  
    3
    2
    1

    Hi Andy,

    I believe the security architecture prevents you posting XML into a dynamic data call, however the way to access the form XML in a DDL is to perform a background save first, and then access the xml through the submission object (or the Txn object if writing a Fluent DDL).

     

    1. Trevor Ward

      Here is some sample js and groovy-fluent code that helped me address this via help from Jeff and Ben: ( if you are using a namespaced JS 'x', need the 'maestro' scoped object refs, but DynamicData must be passed in) function xStateHandler(item, DynamicData) { maestro.Form.backgroundSave().then(function(bsResponse) { x.xStateHandlerInternal(item, DynamicData, maestro.Form, maestro.Util, maestro.Form.data); }); } function xStateHandlerInternal(item, DynamicData, Form, Util, data) { var serviceName = "xml State Dyanmic Data Service"; //dataParams = Form.convertToFieldDataMap(item.properties.inputFieldRefs, data); var enableProgress = true; var progressMsg = "Custom wait message..."; // Show progress indicator if enabled if(enableProgress) Form.showProgress(progressMsg); DynamicData.call(serviceName, dataParams).then(function(response){ if(enableProgress) Form.showProgress(""); console.log(" response: " + response ); //console.log(" first: " + response["first"] ); //console.log(" last: " + response["last"] ); // Fire on success rule Form.fireRule("onSuccess", item, data, response); }).catch(function(err){ if(enableProgress) Form.showProgress(""); // Fire on failure rule Form.fireRule("onFailure", item, data, err); }); } Fluent: import com.avoka.core.groovy.GroovyLogger as logger import com.avoka.tm.vo.* import com.avoka.tm.query.* import javax.servlet.http.* import groovy.json.JsonBuilder import com.avoka.tm.util.Path class xmlStateDyanmicDataService { /* * Perform Form Dynamic Data service call. * * returns: REST response text data */ String invoke(SvcDef svcDef, Txn txn, HttpServletRequest request, User user) { Txn ntx = new TxnQuery() .setId(txn.id) .withFormXml() .firstValue() logger.info ntx Path xmlPath = new Path(ntx.formXml) // whatever you need to do here String firstName = (String) xmlPath.val('/AvokaSmartForm/Name')?:'empty' String lastName = (String) xmlPath.val('/AvokaSmartForm/LastName')?:'empty' logger.info("xmlTest1: " + firstName + " " + lastName) Map result = [:] result.first = firstName result.last = lastName return new JsonBuilder(result).toString() } }

    CommentAdd your comment...
  2.  
    2
    1
    0

    Andy:

     

    David Foster is correct, xml data is removed from dynamic data calls for security reasons.

     

    If you really want to submit the form's data in the dynamic data call, and the suggestion to background save first isn't feasible, you would need to find or build an xml translator to prep the data.  Then build the reverse in the Groovy script.

     

    There is a reason this is not easy to do.  The Submit button is encrypting the form data, protecting any personally-identifiable-information that might be on the form.  So whatever you build please keep data security in mind!

      CommentAdd your comment...
    1.  
      1
      0
      -1

      Seems like a sledgehammer to crack a nut to me. Surely the better way to handle this is to encrypt dynamic data calls in the same way that the submit button does. The data format of the payload doesn't imply anything about the sensitivity of the data, and restricting XML data seems like an artificial and unnecessary restriction in a dynamic data call. My 2c.

        CommentAdd your comment...