Error
If you are trying to get/set values using XPath on Secondary Data Source, you might get the error “Reference to undeclared namespace prefix: dfs”.
Cause
When you are trying to use XPath expression on Secondary Data Source, you must have to declare the namespace that is going to be used in the code. By default, InfoPath does NOT add namespace for Secondary Data Source. You have to add it manually.
Resolution
Select the top most element of the Secondary Data Source, right click on it and go to Properties…

Now copy the namespace shown in the image below.

Now in “script.js” file, add the following line at the top where other namespace is defined.
XDocument.DataObjects("UpdateListItems").DOM.setProperty("SelectionNamespaces",
'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
Please note that “UpdateListItems” is the name of my Secondary Data Source. Replace it with your Secondary Data Source name. Also “dfs” namespace may differ for you so replace it with the namespace you got in Step 2.
Leave a Reply