
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2016 12:17 PM
What is the best way to dynamically create ECC queue records directly from a workflow, AND retrieve the results of the ECC command within the workflow?
In other words, I want to be able to run commands on a linux mid server directly. Then I want to be able to retrieve the results within the workflow, and chose a different workflow action depending on the results of the command.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2018 09:57 AM
The result of ecc_queue.insert() in your code will return the sys_id of the ecc_queue record you created. That is the instruction for the MID server to process. After the MID server processes the command, it will write back another record to the ecc_queue table with the queue 'input.' The payload should contain the sys_id of the record from the "output" queue to which the "input" record is a response.
You can probably find that in the XML in the following node (using XPath): results/parameters/parameter[name='ecc_queue']/value
I say probably because the payload can be different depending on what the MID server is doing. However I'm fairly confident that the response to an "output" queue command will be in this format.
The result of that XPath should match the sys_id of the record you created in your script above.
What you can do is save the sys_id to the workflow scratchpad, then create a series of activities to wait for a period of time, check for the "input" record to appear (instead of XPath, you can query for payloadLIKEparameter name="ecc_queue" value="[sys_id]"), and if nothing has found, use a turnstile to loop back to the wait timer and check again until you find it. Make sure you set the max tried on the turnstile to something reasonable.
Let me know if that helps.
Thanks
Nick

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2016 08:06 AM
Anyone have any suggestions? I was able to create a ECC queue record by simply creating a Run Script activity.
createECCQueue : function(midserver, name, command) {
var ecc_queue = new GlideRecord('ecc_queue');
ecc_queue.initialize();
ecc_queue.agent = 'mid.server.' + midserver;
ecc_queue.name = name;
ecc_queue.queue = 'output';
ecc_queue.topic = 'Command';
ecc_queue.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="name" value="' + command + '"/></parameters>';
ecc_queue.insert();
}
However, what is the best way to retrieve the status of the command from the ECC queue?
This is important for effective status and error handling. I'm surprised there isn't some sort ID that can be queried on the ECC queue to grab the response status. I was thinking:
1 create a Run Script activity and perform a glide query, 2 sort by date, 3 match on the command name 4 grab the xml response 5 parse the response
However that is a bit risky -- what if another workflow is running at the same time and it grabs the wrong response? I would like a more accurate way to check the response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 07:22 AM
any luck finding the answer?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2018 12:03 PM
Hello, Sorry for the delay in response. I solved this and I wrote this post with the details: https://community.servicenow.com/community?id=community_question&sys_id=db8293a1db101fc01dcaf3231f96195b

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2018 09:57 AM
The result of ecc_queue.insert() in your code will return the sys_id of the ecc_queue record you created. That is the instruction for the MID server to process. After the MID server processes the command, it will write back another record to the ecc_queue table with the queue 'input.' The payload should contain the sys_id of the record from the "output" queue to which the "input" record is a response.
You can probably find that in the XML in the following node (using XPath): results/parameters/parameter[name='ecc_queue']/value
I say probably because the payload can be different depending on what the MID server is doing. However I'm fairly confident that the response to an "output" queue command will be in this format.
The result of that XPath should match the sys_id of the record you created in your script above.
What you can do is save the sys_id to the workflow scratchpad, then create a series of activities to wait for a period of time, check for the "input" record to appear (instead of XPath, you can query for payloadLIKEparameter name="ecc_queue" value="[sys_id]"), and if nothing has found, use a turnstile to loop back to the wait timer and check again until you find it. Make sure you set the max tried on the turnstile to something reasonable.
Let me know if that helps.
Thanks
Nick