Here is the initial script that extracts all 3 variables after the initial form load:
// This Script looks at the response to the Message that precedes it and Extracts // variables specific to MOSS InfoPath applications. This is the first script which // extracts 3 variables. EditingSessionId and SolutionId do not change after this // initial extraction, but the CanaryValue does change after each form postback. // Get the Message that immediately precedes this Script. var msg = $context.currentItem.previousItem; // Since there are multiple 'set-cookie' headers in the response, we can't parse // headers using msg.RESPONSE_HTTP_HEADER. Instead we need to get the full response // and parse it down. // Get full response (headers and body) var origText = msg.getResponse(msg.RESPONSE_TEXT); $context.result.postMessage($context.result.LEVEL_INFO, "full response: " + origText); // Extract CanaryValue from cookie (if needed) // var pos = origText.indexOf("Set-Cookie: _InfoPath_CanaryValue"); // var newText = origText.substring(pos + 33); // var pos = newText.indexOf(";"); // newText = newText.substring(0, pos); // $context.result.postMessage($context.result.LEVEL_INFO, "InfoPath_CanaryValue_fromCookie: " + newText); // $prop.set("MessageClip", "InfoPath_CanaryValue_fromCookie", newText); // 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 editingSessionId var editingSessionId = g_objCurrentFormData[3] $context.result.postMessage($context.result.LEVEL_INFO, "InfoPath_editingSessionId: " + editingSessionId); $prop.set("MessageClip", "InfoPath_editingSessionId", editingSessionId); // extract solutionId var solutionId_unencoded = g_objCurrentFormData[4] $context.result.postMessage($context.result.LEVEL_INFO, "InfoPath_solutionId unencoded: " + solutionId_unencoded); $prop.set("MessageClip", "InfoPath_solutionId_unencoded", solutionId_unencoded); // 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);