Call Infopath with JScript... - InfoPath Dev
in

InfoPath Dev

Call Infopath with JScript...

Last post 03-19-2006 07:54 AM by Karsten Brocksieper. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-16-2006 07:34 AM

    Call Infopath with JScript...

    Hello,

    I would like to set values in an infopath form from outside of infopath. Therefore I have written a small javascript to access the Infopath object modell.

    Now I have a problem with setting the information in the appropriate fields in the form.

    In the following you will find my script and everthing works fine --- without the last line. ;-(((

    var oApp = new ActiveXObject("InfoPath.Application");
    WScript.Echo("InfoPath Version: " + oApp.Version);

    var oXDocumentCollection = oApp.XDocuments;
    var oXDocument = oXDocumentCollection.NewFromSolution("file:///C:\\InfopathFormCall.xsn");
    var oXMLDocument = oXDocument.DOM;

    oXMLDocument.setProperty("SelectionNamespaces","xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-01-19T21:16:49'");

    oXMLDocument.selectSingleNode("/my:meineFelder/my:txtTelefon").text = "New value";

    I get the error message that 'oXMLDocument.selectSingleNode(...)' is Null or not an object...

    BTW: 'meineFelder' is the german expression for 'myfields' but replacing this will result in the same error message.

    Can someone help me to get the correct syntax for accessing the selectSingleNode object.

    Any help is greatly appreciated
    Karsten
  • 03-16-2006 02:16 PM In reply to

    Re: Call Infopath with JScript...

    This is a common error and it almost always has to do with your XPath expression. It sounds like you have checked this against your data source to make sure that it is correct, but that's the only action I would suggest.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 03-17-2006 12:31 AM In reply to

    Re: Call Infopath with JScript...

    Hi Matt,

    thank you for your advice. Yes, I know that the problem is the XPath expression but that exactly is my problem ;-((

    I´ve tried various syntax for the XPath expression beginning from

    ...("meineFelder:txtTelefon").text to ...("//my:myFields//my:txtTelefon).Text

    but all without success...

    Therefore I hoped that someone can show me the correct XPath expression in this case.

    Thank you very much.

    Karsten
  • 03-19-2006 07:54 AM In reply to

    Re: Call Infopath with JScript...

    Hello,

    ...in the meantime I have found a solution which I want to share for anyone who is interested in.

    The problem in my code was the correct declaration of the namespace.
    If you don´t declare the -really- exact namespace for the property 'SelectionNamespaces' the above mentioned code will failed.

    You can determine the exact namespace definition for the used form template with the method 'namespaceURI' as I show in the following line:

    var oXMLDocNamespace = oXMLDocument.selectSingleNode("/*[1]").namespaceURI;

    Now you can set the correct value for the 'SelectionNamespaces' property:

    oXMLDocument.setProperty("SelectionNamespaces","xmlns:my='" + oXMLDocNamespace + "'");

    So, the whole working code looks like...

    var oApp = new ActiveXObject("InfoPath.Application");
    var oXDocumentCollection = oApp.XDocuments;
    var oXDocument = oXDocumentCollection.NewFromSolution("file:///C:\\Mytemplate.xsn");
    var oXMLDocument = oXDocument.DOM;
    var oXMLDocNamespace = oXMLDocument.selectSingleNode("/*[1]").namespaceURI;

    oXMLDocument.setProperty("SelectionNamespaces","xmlns:my='" + oXMLDocNamespace + "'");

    oXMLDocument.selectSingleNode("//my:myFields//my:singleFieldname").text = "This is a new value";


    HTH,
    Karsten
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.