Skip to content

Instantly share code, notes, and snippets.

@nicola-attico
Last active May 17, 2022 09:47
Show Gist options
  • Save nicola-attico/c28a007fe529785d1ba4e83d0a3a1014 to your computer and use it in GitHub Desktop.
Save nicola-attico/c28a007fe529785d1ba4e83d0a3a1014 to your computer and use it in GitHub Desktop.
ECCCommandV2 Script Include
var ECCCommandV2 = Class.create();
ECCCommandV2.prototype = {
runCommand: function(server, command) {
var ecc_queue = new GlideRecord("ecc_queue");
ecc_queue.initialize();
ecc_queue.agent = "mid.server." + server;
ecc_queue.payload = '<parameters><parameter name="name" value="' + command + '"/></parameters>';
ecc_queue.queue = "output";
ecc_queue.topic = "Command";
var ecc_sysid = ecc_queue.insert();
gs.debug("ecc_sysid:" + ecc_sysid);
var response_sysid;
var ecc_response = new GlideRecord("ecc_queue");
for (i = 0; i < 60; i++){
gs.sleep(1000);
ecc_response.addQuery("response_to", ecc_sysid);
ecc_response.addQuery("queue", "input");
ecc_response.query();
if (ecc_response.next()) {
response_sysid = ecc_response.sys_id;
response_payload_xml = ecc_response.payload;
gs.debug("response_sysid:" + response_sysid);
return {
"response_sysid": response_sysid,
"response_payload_xml": response_payload_xml
};
}
}
},
type: 'ECCCommandV2'
};
@nicola-attico
Copy link
Author

Execute command on the ServiceNow MID Server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment