- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 05:00 AM
Hi,
I am using the following script in a workflow to query the input record created I have sent a command to the MID Server via the ECC queue.
var ecc = new GlideRecord("ecc_queue");
var source = current.sys_id;
var enc = 'topic!=HeartbeatProbe^topicNOT LIKEqueue.^queue=input^source='+source;
ecc.addEncodedQuery(enc);
ecc.query();
if(ecc.next()) {
var xmlPayload = ecc.payload.getValue('payload');
var payload = gs.getXMLText(xmlPayload, "//stdout");
var array = ['User successfully added to group', 'User exists in the group'];
for (var i = 0; i < array.length; i++) {
if (payload.toString().indexOf(array[i]) > -1 ) {
workflow.scratchpad.user_in_group = 'true';
} else {
workflow.scratchpad.user_in_group = 'false';
}
}
}
I'm looking through the value in <stdout></stdout> and checking the response contains either of the values in my array. When the response is 'User exists in the group', this works as expected and the following if statement activity result is set to 'yes'. When the response is 'User successfully to the group' the activity result is set to 'no' eventhough it should be 'yes.
Any ideas?
Steveb
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 07:14 AM - edited 01-11-2023 08:01 AM
The way the if is written right now, it overwrites a find with a non-find, that is why it is working only one way.
I would do something this:
var ecc = new GlideRecord("ecc_queue");
var source = current.sys_id;
var enc = 'topic!=HeartbeatProbe^topicNOT LIKEqueue.^queue=input^source=' + source;
ecc.addEncodedQuery(enc);
ecc.query();
if (ecc.next()) {
var xmlPayload = ecc.payload.getValue('payload');
var payload = gs.getXMLText(xmlPayload, "//stdout");
var array = [/User\s+successfully\s+added\s+to\s+group/i,
/User\s+exists\s+in\s+the\s+group/i,
];
workflow.scratchpad.user_in_group = array.some(getTesterForPayload(payload));
function getTesterForPayload (payload) {
return function tester (regExp) {
return regExp.test(payload);
};
}
}
On one hand use regular expressions - can be a bit more flexible, at leas case insensitive, on the other use a readily available array method meant exactly for this: to check whether at least one member of an array fulfills a condition (in this case that the text is to be found in the payload).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-11-2023 07:14 AM - edited 01-11-2023 08:01 AM
The way the if is written right now, it overwrites a find with a non-find, that is why it is working only one way.
I would do something this:
var ecc = new GlideRecord("ecc_queue");
var source = current.sys_id;
var enc = 'topic!=HeartbeatProbe^topicNOT LIKEqueue.^queue=input^source=' + source;
ecc.addEncodedQuery(enc);
ecc.query();
if (ecc.next()) {
var xmlPayload = ecc.payload.getValue('payload');
var payload = gs.getXMLText(xmlPayload, "//stdout");
var array = [/User\s+successfully\s+added\s+to\s+group/i,
/User\s+exists\s+in\s+the\s+group/i,
];
workflow.scratchpad.user_in_group = array.some(getTesterForPayload(payload));
function getTesterForPayload (payload) {
return function tester (regExp) {
return regExp.test(payload);
};
}
}
On one hand use regular expressions - can be a bit more flexible, at leas case insensitive, on the other use a readily available array method meant exactly for this: to check whether at least one member of an array fulfills a condition (in this case that the text is to be found in the payload).