Accessing nodes of secondary datasource - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Accessing nodes of secondary datasource

Last post 01-15-2009 06:08 PM by savita. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-15-2009 05:53 AM

    Accessing nodes of secondary datasource

    Hi. I went through some very informative links on namespece definitions and secondary datasources.

    http://www.infopathdev.com/blogs/matt/archive/2006/02/02/Setup-Namespaces-for-a-Secondary-Data-Source.aspx
    http://www.infopathdev.com/forums/p/5299/20981.aspx#20981
    http://www.infopathdev.com/forums/p/10045/35640.aspx#35640
     

    I am using Infopath 2003 SP2, Access 2003 and prg language is VBScript.  I have a form where I need to access a secondary datasource named UserAccess to find the access of the user who logs in.
    The secondary  datasource looks like below:

    myFields
        dataFields
           d:UserAccess

    I have added the following namespacesDefinition in the form which I got in the properties of UserAccess.
    XDocument.GetDOM("UserAccess").setProperty "SelectionNamespaces", "xmlns:ns1=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"""

     The code looks like below:

    Sub btn_Test_OnClick(eventObj)
            dim orig_sql, criteria, new_sql, user_acc
            orig_sql = XDocument.DataAdapters("UserAccess").Command
            msgbox(orig_sql)
            criteria = "SNS002"                              ' hardcoding only for testing
            new_sql = orig_sql + " where userid = '" + criteria + "'"
            msgbox(new_sql)
            XDocument.DataAdapters("UserAccess").Command = new_sql
            XDocument.DataAdapters("UserAccess").Query()
            user_acc = XDocument.getDOM("UserAccess").selectSingleNode("ns1:useracc").value
            msgbox(user_acc)
    End Sub

    The line of code where I try to access the value from useracc column throws an error 'Object required'. I have tried using:
    XDocument.getDOM("UserAccess").selectSingleNode("/ns1:useracc").value
    XDocument.getDOM("UserAccess").selectSingleNode("/ns1:@useracc").value and many other combinations but nothing helped.

    What am I doing wrong? Is the namespacesDefinition wrong?  I intend to use the same logic to check whether a user is entering duplicate data in a column which has unique key constraint.

    Please help!!

    Filed under: , ,
  • 01-15-2009 06:26 AM In reply to

    Re: Accessing nodes of secondary datasource

    Hi,

    Try the following code line.

    user_acc = XDocument.getDOM("UserAccess").selectSingleNode("write the total xpath of the user acc").value

    the total xpath may be like ‘myFields/ dataFields/ns1:UserAccess'

    Also once verify any prefix need to add before the myfields and dataFields.

     

    Or use the following one.

    user_acc = XDocument.getDOM("UserAccess").selectSingleNode("//ns1:UserAccess").value

     

    Swathip
    www.ggktech.com
  • 01-15-2009 06:08 PM In reply to

    Re: Accessing nodes of secondary datasource

    Hi swathip. Thanks for your help. I solved the problem.

    I had used selectSingleNode("/dfs:myFields/dfs:dataFields/d:UserAccess/@useracc").value in the beginning and many other combinations. But my namespace definition was going all wrong. I changed the namespace definition.

    FROM
    XDocument.GetDOM("UserAccess").setProperty "SelectionNamespaces", "xmlns:ns1=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"""

    TO
    XDocument.GetDOM("UserAccess").setProperty "SelectionNamespaces", "xmlns:d=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"" xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"""

    And then I could use the following to access useracc field from the secondary datasource.

    user_acc = XDocument.getDOM("UserAccess").selectSingleNode("/dfs:myFields/dfs:dataFields/d:UserAccess/@useracc").value

    Thanks again.

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