Dev Space

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.
SOLVED

HTML/Javascript plugin - how to send a synchronous request

DavidVonka
Alteryx
Alteryx

There is something wrong with this code

 

Alteryx.Plugin.II_PushRecords = function (data) {
Alteryx.Engine.SendMessage.Warning("Before request");
$.ajax({
url: 'https://v1-17-1-4.semanta.cloud/x/admin/cleanstage',
type: "GET",
async:false,
data: {
loadCode: 'xxx',
username:'admin',
password:'somepassword'
},
success: function () {
Alteryx.Engine.SendMessage.Warning("success");
},
error: function () {
Alteryx.Engine.SendMessage.Warning("error");
}
});
Alteryx.Engine.SendMessage.Warning("After request");

Alteryx.Engine.SendMessage.PushRecords("T2", data.Records);
};

It is a part of a plugin that has one input and one output. I want the output to be exactly the same as the input, but as a side-effect, I want to synchronously (i.e. with blocking) call a web service. On running this, I get the following error message

 

Error: Designer x64: The Designer x64 reported: InboundNamedPipe::ReadFile:  The pipe has been ended.

the web service is not called (I can check on the server, but also I see very little going on in Fiddler).

 

A few points

  1. when I remove the request, passing the data through the tool works fine. Output is input, no problem there.
  2. when I make the request asynchronous, the tool will interrupt when it has finished processing
  3. the request actually works, I can run the jquery code (replacing the SendMessage by an alert) in Chrome if I start it with same origin policy disabled
  4. I do have $.ajax, if the server is http and not https and I set async:true, I can observe that the request occasionally makes it before the tool kills it

Thanks a lot !

1 REPLY 1
DavidVonka
Alteryx
Alteryx
        success: function () {
Alteryx.Engine.SendMessage.Warning("success");
Alteryx.Engine.SendMessage.PushRecords("T2", data.Records);
Alteryx.Engine.SendMessage.CloseOutput(Alteryx.Plugin.DefineConnections().OutgoingConnections[0].name);
Alteryx.Engine.SendMessage.Complete();

},
error: function () {
Alteryx.Engine.SendMessage.Warning("error");
Alteryx.Engine.SendMessage.PushRecords("T2", data.Records);
Alteryx.Engine.SendMessage.CloseOutput(Alteryx.Plugin.DefineConnections().OutgoingConnections[0].name);
Alteryx.Engine.SendMessage.Complete();

}

The key here is to put all the  finalization code into the callbacks ! That includes the PushRecords that I wrongly called at the end of the method and also the code that is usually in the Alteryx.Plugin.II_AllClosed method. 

 

All hail JP Kabler for the much needed hint.