Switching to Error Fields

J

J_A_Z_Z

Is there a way to "go to next error" by way of script?
Im looking for a nice way to go to errors that are being caught on different views.
 
H

Hagen Green [MSFT]

Use this code to figure out what view has an error:

// find view with node error
// search each view...
for (var i = 0; i < XDocument.ViewInfos.Count; i++)
{
// create an XML DOM to load the view into
var oNewDoc = new ActiveXObject("MSXML2.DOMDocument.5.0");
// set the DOM selection namespaces
oNewDoc.setProperty("SelectionNamespaces",
'xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"');
// load the view xsl
oNewDoc.load(XDocument.ViewInfos.Name + ".xsl");
// select all bound controls in this view
var oBindingNodes = oNewDoc.selectNodes("//@xd:binding");
// for each binding within this view...
for (var j = 0; j < oBindingNodes.length; j++)
{
// For each error in our error board
for (var k = 0; k < XDocument.Errors.Count; k++)
{
// get the error's node name
var errorNodeName = XDocument.Errors.Item(k).Node.nodeName;
// check if an error's node name is in our view
if (errorNodeName == oBindingNodes[j].text)
{
// ta-da! we have an error in this view, tell the user
XDocument.UI.Alert(errorNodeName + " has an error in " +
XDocument.ViewInfos.Name);
}
}
}
}
}

But instead of doing the Alert to show the user what view has the error,
simply switch to the view by called View.SwitchView. Then get the node via
the error by using Errors.Item(k).Node. Next use View.SelectNodes(node) or
SelectText(node) (depending on if the control is structural or
text-editable) to select the control within the view.

The hardest part of what you are trying to do is to show the view with the
error. This is accomplished by the above code. If you try to just do the
SelectNodes/Text, it will fail if the error isn't on the current view.

--Hagen
This posting is provided "AS IS" with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top