I want to create function in infopath form that get sharepoint list value. - InfoPath Dev
in

InfoPath Dev

I want to create function in infopath form that get sharepoint list value.

Last post 08-17-2010 11:40 PM by Bhavin Sankhat. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 08-12-2010 12:08 AM

    I want to create function in infopath form that get sharepoint list value.

     Hello all,

    I am really new to infopath. I have sharepoint list that have same column Firstname and Lastname and age.I have infopath form that contain two dropdown controls for firstname and lastname and one textbox for age. Now i want to write function that can take argument as selected values from both the dropdown and get value of corresponding age from sharepoint list and fill age into textbox.

    Any help would be appreciated.

     

    Thank in advance.

     

    Bhavin A Sankhat
    Filed under:
  • 08-12-2010 05:48 AM In reply to

    Re: I want to create function in infopath form that get sharepoint list value.

    Can you use code in your form? If so let me know, i'll help you out with the code. If not, i'm afraid i do not know how.

  • 08-12-2010 03:31 PM In reply to

    Re: I want to create function in infopath form that get sharepoint list value.

    Hi, you can certainly do that with codes but if you don't want to use codes I think it's possible

    I suppose you have a list with first name, last name, full name and age columns. You can create a secondary data connection with this list and populate your dropdowns. You add a field and you put as default value: concat(My:last name; " "; My:first name).After that you add a default value to your age field with your secondary data connection and use a filter (your newfield = fullname of your data connection)

  • 08-12-2010 10:18 PM In reply to

    Re: I want to create function in infopath form that get sharepoint list value.

     Hello,  Thanks for reply. yes i use code in my infopath form. So please let me know how can i do this?

    I am stuck here and can't find any suggestion. Thank you. 

    Bhavin A Sankhat
    Filed under:
  • 08-16-2010 05:49 AM In reply to

    Re: I want to create function in infopath form that get sharepoint list value.

    First, you need to set an onChange event on your 2 dropdown boxes. To do so, right click your dropdown boxes --> programming --> change event. This will create a visual studio project with an empty function for your dropdown box. In this function, write this code (or something similar) :

    XPathNavigator root = MainDataSource.CreateNavigator();
    string FirstName = root.SelectSingleNode("<XPath of your FirstName dropdown box>", NamespaceManager).Value;
    string LastName = root.SelectSingleNode("<XPath of your LastName drop down box>", NamespaceManager).Value;

    SPSite oSiteCollection = new SPSite(<URL of your server, eg http://portal/>);
    SPWeb oWebsiteSrc = oSiteCollection.AllWebs["<URL of the site containing the sharepoint list, eg /sites/finance/expenseaccount>"];
    SPList oList = oWebsiteSrc.Lists["<Name of your list>"];

    string camlQuery = "<Where><And><Contains><FieldRef Name='Name of the FirstName column'/><Value Type='Text'>" + FirstName + "</Value></Contains><Eq><FieldRef Name='Name of the LastName column' /><Value Type='Text'>" + LastName + "</Value></Eq></And></Where>";
    SPQuery query = new SPQuery();
    query.Query = camlQuery;

    SPListItemCollection collListItemsSrc = oList.GetItems(query);

    root.SelectSingleNode("<XPath of your Age Field>", NamespaceManager).SetValue(collListItemsSrc[0].GetFormattedValue("<Name of the Age column>"));

     

    This code is C#.

  • 08-17-2010 11:40 PM In reply to

    Re: I want to create function in infopath form that get sharepoint list value.

     Thanks a lot for your help. It works fine. Again Thank you..

    Bhavin A Sankhat
    Filed under:
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.