none
Comparing Infopath field with Sharepoint list items

    Question

  • Hi,

    I want to compare an Infopath field to the sharepoint list items... how do I do the comparison??

    I have a sharepoint list of admin names and this list has to be compared with the current user login ID in Infopath 2010. I am using the Username() in infopath. If they are equal, the current user is an admin and will be able to edit all fields in the form.

    thanks

    Friday, March 1, 2013 7:07 AM

Answers

  • I do something like this frequently, using rules in InfoPath.

    For example, I'll have a SharePoint list of admins and in my form I have a section that I only want visible to admins. In my admin list, I have "userID" as a column.

    In my form, I have a rule on the section that will hide the section if "All occurrences of userID are not equal to user()"

    You'll notice than when you're building your rule that compares values in the SharePoint list, you can choose "all occurrences of value" from the dropdown:


    Planet Technologies || SharePoint Task Force

    Friday, March 1, 2013 11:10 PM

All replies

  • Hi,

    You need to create a data connection with sharepoint list so you can get the data from list to infopath form. Once you get the list data in form then you can compare it easily.

    See blog blog to create list connection:

    http://blogs.msdn.com/b/infopath/archive/2010/05/06/sharepoint-list-data-connections-in-infopath-2010.aspx

    Let us know in case any issue


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Please feel free to unmark answer if does not resolves your problem.

    Friday, March 1, 2013 8:02 AM
    Moderator
  • I have already created the data connection. I am not able to compare the infopath field with multiple items in the list.

    For eg ..My list has items A,B,C and D. the infopath field is IP1. How do I compare IP1 with first A, then B, and so on. If IP1 =A, then IP1 is an Admin user. If IP1 is not equal to A, then check if IP1=B and so on. I am not able to increment to the next item in the list from the infopath form.
    Friday, March 1, 2013 8:13 AM
  • Ok, i thought just compare with one list item. Now you can use CAML query to search field value in list and based on result you can perform other action. Just add one button on form to execute belwo code:

    using (SPSite site = SPContext.Current.Site)             
    {using (SPWeb web = site.OpenWeb())
    {   
      SPList list = web.Lists["ListName"];                    
       SPQuery qry = new SPQuery();
       qry.Query= "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>hello</Value></Eq></Where>";
       SPListItemCollection items = list.GetItems(qry);
      if(items.Count = 0)
    {
    here you can perform any operation if no match found
    } 
    }}
    Hope it could help


    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"

    Whenever you see a reply and if you think is helpful, click "Alternate TextVote As Helpful"! And whenever you see a reply being an answer to the question of the thread, click "Alternate TextMark As Answer

    Please feel free to unmark answer if does not resolves your problem.

    Friday, March 1, 2013 8:24 AM
    Moderator
  • thanks for the code..just wondering if its possible with Rules in infopath. i want to avoid writing a custom code..
    Friday, March 1, 2013 9:37 AM
  • I do something like this frequently, using rules in InfoPath.

    For example, I'll have a SharePoint list of admins and in my form I have a section that I only want visible to admins. In my admin list, I have "userID" as a column.

    In my form, I have a rule on the section that will hide the section if "All occurrences of userID are not equal to user()"

    You'll notice than when you're building your rule that compares values in the SharePoint list, you can choose "all occurrences of value" from the dropdown:


    Planet Technologies || SharePoint Task Force

    Friday, March 1, 2013 11:10 PM
  • Thanks ronald...that worked for me !
    Monday, March 4, 2013 7:34 AM