Pulling a single value, either from db or SP List - InfoPath Dev
in

InfoPath Dev

Pulling a single value, either from db or SP List

Last post 11-21-2006 10:25 AM by tkflick. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 11-16-2006 12:07 PM

    • tkflick
    • Not Ranked
    • Joined on 11-14-2006
    • USA
    • Posts 2

    Pulling a single value, either from db or SP List

    I have 4 types of users. Each type of user will see a slightly different version of my form. In the OnLoad event, I can get the user_name from the System.Environment.UserName command. I then want to use that user name to query a Sharepoint list that contains the access_level associated with that user_name. I would then use the access_level to decide which View to load.

    How do I return just the access_level associated with the user_name, and then grab the returned value so that I can use it to decide which view to display?

    If anyone can point me in the right direction, I would be most greatful.

    Thanks very much,
    Tim
  • 11-20-2006 10:39 PM In reply to

    Re: Pulling a single value, either from db or SP List

    Hi Tim,
    There are a couple HowTos written that explain how to get/set data from SharePoint lists. Also, Chapter 9 in my book describes this. Go th the "Search InfoPathDev for:" text field and enter "SharePoint list my filter". Let me know if you don't find it.
    Regards,
    Patrick Halstead
    Project Manager at Qdabra
  • 11-21-2006 10:25 AM In reply to

    • tkflick
    • Not Ranked
    • Joined on 11-14-2006
    • USA
    • Posts 2

    Re: Pulling a single value, either from db or SP List

    Thanks for the reply Patrick.

    I've found a couple of examples that might work, but they are in J Script and I'm having trouble converting to C#. I think I'm pretty close here, but can't seem to get the last little bit. Directly below is the edited version of the example I found on InfopathDev.com. Below that is the unedited version of what I found.

    If I'm on the right path and can get the loop working (big If's, I know), I think I'm golden.

    Any insight on getting that while loop to loop thru the items in the List?

    // NEED THIS DECLARATION IN C#
    // I THINK IT WOULD BE:
    // IXMLDOMDocument3 oSharePointDom = (IXMLDOMDocument3)thisXDocument.DataObjects["AccessLevelList"].DOM;
    var oSharePointDom = XDocument.GetDOM( "AccessLevelList" );

    // THIS APPEARS TO WORK AS IS... AT LEAST I GET NO COMPILE ERRORS AT THIS POINT
    oSharePointDom.setProperty("SelectionNamespaces","xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution'");

    // I DON'T NEED THE LOCAL DOM SINCE I'M NOT RESETTING ANY ITEMS ON MY FORM, JUST LOOKING FOR THE ACCESS LEVEL.. SO I'VE REMOVED THIS PART

    // I THINK THIS DECLARATION SHOULD BE:
    // IXMLDOMNode nLSharedItems = oSharePointDom.selectNodes("/dfs:user_id/dfs:access_level");
    var nlSharedItems = oSharePointDom.selectNodes( "/dfs:user_name/dfs:access_level" );


    // WITHOUT THE LOCAL DOM TO COMPARE AGAINST, I'M NOT SURE OF THE SYNTAX FOR THE COMPARISON IN THE LOOP
    // I DON'T HAVE THE "nSharedItem" FOR THE LOOP COMPARISON AND THERE IS NO "NEXTNODE" AVAILABLE IN C#
    while( (nlSharedItems.nextNode() ) != null )
    {

    // ONCE INSIDE THE LOOP, I WILL RUN THE COMPARISON AGAINST THE USER_NAME
    if(sUserName == nlSharedItem.selectSingleNode("@user_name").text)
    {
    sUserAccess = nlSharedItem.selectSingleNode("@access_level");
    }

    }




    THIS IS THE CODE I CHANGED TO TRY AND MAKE IT WORK FOR ME IN C#:

    // Get the updated version of the List
    // If the user is offline, the code will skip to the "catch" block below
    XDocument.DataObjects["Products Online"].Query();

    // Get the ShareList DOM
    var oSharePointDom = XDocument.GetDOM( "Products Online" );
    // Setup the Namespaces
    oSharePointDom.setProperty("SelectionNamespaces",
    'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' );

    // Get the local DOM - to does not use namespaces
    var oLocalDom = XDocument.GetDOM( "Products Offline" );

    // Get a sample cached list node that we will need to clone later
    var nSampleProductNode = oLocalDom.selectSingleNode( "/CachedList/Products/Product" );

    // Remove all of the items from the local copy of the list
    oLocalDom.selectNodes( "/CachedList/Products/Product" ).removeAll();

    // Loop through all of the items in the SharePoint List
    var nlSharedItems = oSharePointDom.selectNodes( "/dfs:myFields/dfs:dataFields/dfs:Products" );

    while( (nSharedItem = nlSharedItems.nextNode() ) != null )
    {
    // Create a new row from the sample
    var nNewLocalCacheRow = nSampleProductNode.cloneNode(true);

    // Set the values
    nNewLocalCacheRow.selectSingleNode( "@ID" ).text = nSharedItem.selectSingleNode( "@ID" ).text;
    nNewLocalCacheRow.selectSingleNode( "@Name" ).text = nSharedItem.selectSingleNode( "@Name" ).text;
    nNewLocalCacheRow.selectSingleNode( "@Description" ).text = nSharedItem.selectSingleNode( "@Description" ).text;

    // Append to to our local cached list
    oLocalDom.selectSingleNode( "/CachedList/Products" ).appendChild( nNewLocalCacheRow );
    }
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.