how to create a javascript in mendix to read a file

0
i am looking for some help about reading text f ile or xml file from a javascript   Please advise with documentation and example Thanks Daniel  
asked
4 answers
1

Start with this script, calling it from a nanoflow action:

<script language="JavaScript">
  // Create a connection to the file.
  var Connect = new XMLHttpRequest();
  // Define which file to open and
  // send the request.
  Connect.open("GET", "Customers.xml", false);
  Connect.setRequestHeader("Content-Type", "text/xml");
  Connect.send(null);
  // Place the response in an XML document.
  var TheDocument = Connect.responseXML;
  // Place the root node in an element.
  var Customers = TheDocument.childNodes[0];
  // Retrieve each customer in turn.
  for (var i = 0; i < Customers.children.length; i++)
  {
   var Customer = Customers.children[i];
   // Access each of the data values.
   var Name = Customer.getElementsByTagName("Name");
   var Age = Customer.getElementsByTagName("Age");
   var Color = Customer.getElementsByTagName(
     "FavoriteColor");
   // Write the data to the page.
   document.write("<tr><td>");
   document.write(Name[0].textContent.toString());
   document.write("</td><td>");
   document.write(Age[0].textContent.toString());
   document.write("</td><td>");
   document.write(Color[0].textContent.toString());
   document.write("</td></tr>");
  }
</script>

 

answered
0

Can you please tell us what it is you are trying to accomplish? 

answered
0

Just thinking aloud with you here. If your use case is creating a complete new environment this setup will not work. If you however want to create a new customer in a multi tenant environment it would be possible if you do this from a different environment. We use this for instance to create new customers in our multitenant environment. These clients are created from our support environment. So in our support environment we do the setup and the result is that the client is created with the right setup. All done with REST services.

Regards,

Ronald

answered
0

Solution:

// This file was generated by Mendix Modeler.

//

// WARNING: Only the following code will be retained when actions are regenerated:

// - the code between BEGIN USER CODE and END USER CODE

// Other code you write will be lost the next time you deploy the project.

 

/**

* @param {string} p_microflowname

* @param {MxObject} p_object

* @returns {boolean}

*/

function ExecuteMicroflowWithParameter(p_microflowname, p_object) {

    // BEGIN USER CODE

    mx.data.action({

        params: {

            actionname: microflowName

        },

origin: this.mxform,

        callback: function (obj) {

            console.info("microflow OK");

        },

        error: function (error) {

            console.info("microflow not ran OK");

        },

onValidation: function(validations) {

console.info("There were " + validation.length + " validation errors");

        }

    });

    // END USER CODE

}

answered