locked
Sharepoint / Lightswitch userlist query issue RRS feed

  • Question

  • Hi,

    We are having Sharepoint 2013.

    MeetingList is a sharepoint list. MeetingList has a column Attendees of type Person or Group with allow multiple selection enabled.

    One meeting will have many Attendees. In the sharepoint webpart if we can add filter as attendee equal  Me  it will give only the meetings where the loggedin user is one of the attendee.

    We are developing HTML5 lightswitch application for the same functionality.

    In this application we want to get list of meetings for the logged in user where the logged in user is one of the attendee.

    Pls find below the screenshot of lightswitch Designer for the list.

    Please advice how we can filter the meetinglist for the above functionality in the lightswitch HTML application.

    Thanks,

    Abdul raheem

    • Edited by s_a_raheem Monday, September 9, 2013 6:33 AM
    Thursday, September 5, 2013 12:45 PM

All replies

  • Hello,

    I am not 100% sure if it still applies to the latest iteration of LightSwitch but previously you couldnt change the shape of the query in the _PreProcess (which is what it thinks you are trying to do with the join). Instead you could get a list of meetings the participant is in and then use that to filter the query like below:-

    var PartyPeople = (from meetingParticipants mp in meetingParticipants
    where mp.Account == this.Application.User.Name
    select mp.Account).ToList().Cast<string>();
    
    query = from item in query where PartyPeople.Contains(item.Account) select item;

    There may be a few errors in your table\field names but the principal is there and it is not changing the shape of the query.

    HTH :)


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Thursday, September 5, 2013 3:32 PM
    Thursday, September 5, 2013 3:32 PM
  • Do you need to join on the Name, like:

    string UserName = this.Application.User.Name;

    query = from meetingsList in query from meetingParticipants in meetingsList.Participants where meetingParticipants.Account.Name == UserName select meetingsList;



    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Thursday, September 5, 2013 5:30 PM
  • Hi,

     Thanks for your adivce. Tried below code as per your suggestion. It's giving error "Not Implemented
    Inner exception message:The method 'Contains' is not supported."

    partial void myMeeitngs_PreprocessQuery(ref IQueryable<MeetingCalendar> query)
            {
     var PartyPeople = (from meetingsList in query
                from mp in meetingsList.Participants
                where mp.Account == this.Application.User.Name
                select mp.Account).ToList().Cast<string>();
                query = from meetingsList in query
                        from mp in meetingsList.Participants
                        where PartyPeople.Contains(mp.Account)
                        select meetingsList;
            }

    Hello

    I think you have misinterpreted my answer. What I am saying you do is you first create a list of participants which you hold in the PartyPeople variable. You then query the MeetingList table to see if the participant is contained within it.

    Although after reading Michaels answer and re-reading your question I am inclined to agree with him. If the participant is a column within the table why not just create a query on the MeetingList table that has a parameter of user and then link that user on Created of the app to filter out all the people?


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, September 6, 2013 2:14 PM
  • Do you need to join on the Name, like:

    string UserName = this.Application.User.Name;

    query = from meetingsList in query from meetingParticipants in meetingsList.Participants where meetingParticipants.Account.Name == UserName select meetingsList;



    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com


    Thanks for your suggestion. Account itelf a string field. It's doesn't have Name attribute.
    Friday, September 6, 2013 2:14 PM
  • Hello,

    I am not 100% sure if it still applies to the latest iteration of LightSwitch but previously you couldnt change the shape of the query in the _PreProcess (which is what it thinks you are trying to do with the join). Instead you could get a list of meetings the participant is in and then use that to filter the query like below:-

    var PartyPeople = (from meetingParticipants mp in meetingParticipants
    where mp.Account == this.Application.User.Name
    select mp.Account).ToList().Cast<string>();
    
    query = from item in query where PartyPeople.Contains(item.Account) select item;

    There may be a few errors in your table\field names but the principal is there and it is not changing the shape of the query.

    HTH :)


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Hi,

    Thanks for your adivce. Tried below code as per your suggestion. It's giving error"Not Implemented
    Inner exception message:The method 'Contains' is not supported."

    partial void myMeeitngs_PreprocessQuery(ref IQueryable<MeetingCalendar> query)
            {
     var PartyPeople = (from meetingsList in query
                from mp in meetingsList.Participants
                where mp.Account == this.Application.User.Name
                select mp.Account).ToList().Cast<string>();
                query = from meetingsList in query
                        from mp in meetingsList.Participants
                        where PartyPeople.Contains(mp.Account)
                        select meetingsList;
            }
    Friday, September 6, 2013 2:15 PM
  • Do you need to join on the Name, like:

    string UserName = this.Application.User.Name;
    query = from meetingsList in query
    from meetingParticipants in meetingsList.Participants
    where meetingParticipants.Account.Name ==  UserName
    select meetingsList;


    Thanks for your suggestion. Account itelf a string field. It's doesn't have Name attribute.
    I think that you should try the following:
    string UserName = this.Application.User.Name;
    
    query = from meetingsList in query
    where meetingList.participant ==  UserName
    select meetingsList;


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Friday, September 6, 2013 2:21 PM
  • Thanks, it will work fine if onely one participant. but the issue is more than one participant in a meeting.
    Friday, September 6, 2013 5:12 PM
  • One meeting can have multiple participants. Issue is light switch is not supporting queries with all, any , contains. So, looking for a way to achieve this.
    Friday, September 6, 2013 5:20 PM
  • Dear Mr.Michael and Mr.Otis Ranger , I have updated teh question to provide better clarification. Hope this gives the exact requirement.

    Thanks,

    Abdul raheem

    Monday, September 9, 2013 6:37 AM
  • I never seem to do with these types of questions when I am not at the computer. The contains example noted earlier should work. Why it doesn't I cannot say, sorry.

    Unleash the Power - Get the LightSwitch HTML Client book

    http://LightSwitchHelpWebsite.com

    Monday, September 9, 2013 12:31 PM
  • Hello

    Things are still muddled but by having a quick play on the laptop i think i can see why you are not getting the Contains method. When you create the PartyPeople variable you have to make sure that you are setting the var to the table type within the query.

    I have mocked up something that I think will work. If you create a query based on your NDC_MeetingCalendar called Query1 you could then use the following (or something similar)

            partial void Query1_PreprocessQuery(ref IQueryable<NDC_MeetingCalendar> query)
            {
                var PartyPeople = (from UserInformationList item in UserInformationLists where item.Name == this.Application.User.FullName select item).ToList().Cast<string>();
    
                query = from item in query where PartyPeople.Contains(item.Attendees) select item;
            }

    The key in the example is that the variable "item" within the PartyPeople query is being set as type UserInformationList which gives you access to the Contains that you need.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Otis Ranger Monday, September 9, 2013 1:21 PM
    Monday, September 9, 2013 1:21 PM
  • Dear Mr. Otis,

     First of all thank you very much for putting effort to propose a solution.

    1)              var PartyPeople = (from UserInformationList item in UserInformationLists where item.Name == this.Application.User.FullName select item).ToList().Cast<string>();

    will have only the logged in person as the UserInformationList of sharepoint is nothing but the list of users. It won't be having more than one value for any user.

    2) PartyPeople.Contains(item.Attendees) gives compile error as it expects sigle value inside contains not a list. In our case Attendees is a list.

    3) By default Sharepoint lists with multiple vlaues enabled colums are haing many to many relationship.So,Lightswitch is not supporting such a  relationship.

    Is there any other way to filter the retrieved data from sharepoint to further filter in the serverside in lightswitch.

    Thanks,

    Abdul Raheem

    Tuesday, September 10, 2013 9:44 AM
  • Im sorry but you still arent making much sense. I will use your numbering to reply.

    1) This I suspected before which is why I said to not even link to the table and just look for the logged in user on the attendee. i.e. on the last code snippet I did ignore the PartyPeople and just use query = from item in query where item.Attendees* == this.Application.Name.FullName;  
    *= You may have to use item.Attendees.Name or something similar but as we dont know the data structure it is pure guesswork

    2)This makes no sense at all. The whole point of the contains is that you can check on more than one thing. If you couldnt then you would just use "==". I think you need to show more of the code and data structure in order for pepole to help because it is too confusing at the moment.

    3)LS doesnt do many to many out of the box, but that doesnt mean that you cant query the data.

    I think that without further detail from you I wont be able to help you any more than i have, sorry.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Tuesday, September 10, 2013 10:23 AM
  • Dear Otis,

     Your support on this issue is really appreciated. thanks again.We are trying to query sharepoint list which has hierarchial relationship  not the relational database.

    As you can see in the data design diagram attendees field type is UserInformatiionListcolection not jut userinformationist.

    Hope this clarifies.

    Thanks again,

    Abdu raheem

    Tuesday, September 10, 2013 5:04 PM
  • I have never done this so I am at the limit of my knowledge. Although just 10 minutes of <insert search engine name here> has brought up a list of some really interesting tutorials and walkthroughs with LightSwitch and SharePoint. Maybe one of these will help?

    How to Create A Lightswitch App that uses SharePoint Data

    Developing a SharePoint Application Using LightSwitch

    Using SharePoint Lists as LightSwitch Entities and with CSOM

    They all have links within them to other tutorials and resources.


    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    Wednesday, September 11, 2013 9:33 AM
  • Dear Otis, Thank you very much for your extensive support. As you mentioned there were lot of resources for lightswitch /sharepoint . But I couldn't find a solution for my case. Let consider this as a LINQ / ODATA / SHAREPOINT issue rather lightswitch issue and post in suitable other forum. Thanks, Abdul Raheem
    Wednesday, September 11, 2013 4:44 PM