Here is the second script that extracts just the CanaryValue after each form postback:
// This Script looks at the response to the Message that precedes it and Extracts // variables specific to MOSS InfoPath applications. This is the second script which // extracts the CanaryValue after each form postback. // Get the Message that immediately precedes this Script. var msg = $context.currentItem.previousItem; // Get full response (headers and body) var origText = msg.getResponse(msg.RESPONSE_TEXT); $context.result.postMessage($context.result.LEVEL_INFO, "full response: " + origText); // Find 'var g_objCurrentFormData' definition in response and put it into a variable (newText) // This is just a string that contains the javascript 'var ...' string. // This is step 1; It is not parse-able in this format. var pos = origText.indexOf("var g_objCurrentFormData"); var newText = origText.substring(pos + 0); var pos = newText.indexOf(";"); newText = newText.substring(0, pos); $context.result.postMessage($context.result.LEVEL_INFO, "g_objCurrentFormData array: " + newText); // The next step is to actually execute the 'var ...' javascript. // Since the string is simply setting the contents of the var string to the // variable g_objCurrentFormData, we can run it using the eval function. // Running eval(newText) below will load the g_objCurrentFormData string into // an array that the the script can navigate. eval (newText); // Extract CanaryValue from Response Body var canaryValue = g_objCurrentFormData[25] $context.result.postMessage($context.result.LEVEL_INFO, "Canary Value from Response Body: " + canaryValue); $prop.set("MessageClip", "InfoPath_CanaryValue_fromResponseBody", canaryValue);