I'm starting up a headless client on the server via code and executing a global method. So far, so good.
However, I then want to be able to use that spawned client for other users to do the same thing.
So, I'm using:
- Code: Select all
headlessClient = plugins.headlessclient.getClient(headlessID)
I have the UUID of the client (as I captured it after I created it) - but still the call to getClient gives me a null or invalid result.
I've tried a number of approaches - including this one:
- Code: Select all
var headlessClient = null;
var cnt = application.getClientCountForInfo("PDFBOT");
if(cnt == 0) {
//not running - create it
// Creates a headless client that will open the given solution.
headlessClient = plugins.headlessclient.createClient("myBotSolution", "userName", "password", null);
} else {
//running - get the ID
var botID = null;
var clients = plugins.maintenance.getConnectedClients();
for (var i = 0; i < clients.length; i++) {
if(utils.stringPatternCount(clients[i].getUserName(),"PDFBOT") > 0) {
//found the BOT
var botID = clients[i].getClientID();
break
}
}
/*** THIS CORRECTLY RETURNS THE HEADLESS CLIENT ID OF: "FBDAD129-4DF2-4CC4-8508-747EFC23EFC8" ***/
if(botID) {
// Gets an existing headless client for the given client uuid.
headlessClient = plugins.headlessclient.getClient(botID); // <----- HERE IS WHERE IT'S NOT WORKING
} else {
application.output("Your PDF generation request FAILED because we couldn't find a running bot." );
return;
}
}
if (headlessClient != null && headlessClient.isValid()) {
var x = new Object();
x.value = myRecordID;
headlessClient.queueMethod(null, "runCronMethod", [x], globals.PDFBotCallback);
} else {
application.output("Error - Your PDF generation request FAILED to queue");
}
Is there anything obvious I'm missing here?
Any help would be appreciated!
Bob