title: Javascript trigger two time
body: <p>I use Javascript to trigger a Flow when I want to change the state. Everything worked fine but the JavaScript function triggered two times when I try to change the state my record:</p>
  
  <pre><code>storno=function (executionContext){
  var functionName = "storno";
  var formContext = executionContext.getFormContext();
     if(formContext.getAttribute("statecode").getValue() == 3)
      { 
          try
          {
              var data= {"id": ""};
              data.id = formContext.data.entity.getId();
              var requestUrl ="https://prod-161.westeurope.logic.azure.com:443/workflows/be86749dcdccdca10458/triggers/manual/paths/invoke?api-version=2016-06-01&amp;sp=%2Ftriggers%2Fmanual%2Frun&amp;sv=1.0&amp;sig=mPDRr3nKLQEN6oWMk1JE-laDKwAKe_dx46fqKYw"; 
  
          var req = new XMLHttpRequest();
          req.open("POST",requestUrl,true);
          req.setRequestHeader("Accept","application/json");
          req.setRequestHeader("Content-Type","application/json; charset=utf-8");
          req.setRequestHeader("OData-MaxVersion","4.0");
          req.setRequestHeader("OData-Version","4.0");
          req.onreadystatechange = function()
          {
              if(this.readyState == 4 || this.readyState == 2)
              {
                  req.onreadystatechange = null;
  
                  if (this.status == 200 || this.status == 204 || this.status == 202)
                      {
                          formContext.data.refresh(true);
                      }
                  else{
                      var error = JSON.parse(this.response).error;
                      }
              }
          };
          req.send(JSON.stringify(data)); 
      }
      catch(ex)
      {
          Obj_RunFlow.throwError(functionName,ex.massage);
      }
  }
  </code></pre>
  
  <p>};</p>