Set all play counts = 0 if “authid” is not returned
// Get the Message two ago that precedes this Script.
var msg = $context.currentItem.previousItem.previousItem;
// Get the response to the Message.
var response = msg.getResponse(msg.RESPONSE_HTTP_BODY);
// Was there a response?
if (response == null)
{
// There was no response.
// Output an informational message and set all subsequent play counts = 0.
$context.result.postMessage($context.result.LEVEL_INFO, "Message " + msg.name + " received no response to validate.");
var nextItem = $context.currentItem.nextItem;
while (nextItem != null)
{
nextItem.setRepeat(nextItem.REPEAT_TIMING_SERIAL, nextItem.REPEAT_TYPE_COUNT_CONSTANT, 0, nextItem.REPEAT_DISTRIBUTION_CONSTANT, 0);
nextItem = nextItem.nextItem;
}
msg.clearResponse();
}
else
{
// There was a response.
// Get the value of the Global Property.
// var stringToFind = $globalprop.value("Global property list name here", "Global property name here");
// string to find; hard coded
var stringToFind = "authid";
// Determine if the value exists in the response.
var searchIndex = response.indexOf(stringToFind);
// If the value does not exist in the response, output an error and set all subsequent requests to have a play count=0.
if (searchIndex == -1)
{
var details = "Response:\n" + response + "\n\nValue searched for:\n" + stringToFind;
$context.result.postMessage($context.result.LEVEL_ERROR, "Login failed because authid not found " + msg.name, details);
var nextItem = $context.currentItem.nextItem;
while (nextItem != null)
{
nextItem.setRepeat(nextItem.REPEAT_TIMING_SERIAL, nextItem.REPEAT_TYPE_COUNT_CONSTANT, 0, nextItem.REPEAT_DISTRIBUTION_CONSTANT, 0);
nextItem = nextItem.nextItem;
}
msg.clearResponse();
}
}