locked
LightSwitch HTML Client People Picker RRS feed

  • Question

  • What would be the best way to implement a people picker in the LightSwitch HTML client?

    Does SharePoint 2013 (on-premises) expose an OData service that I could connect to as a datasource and then query for users?

    I could then envisage providing a popup on one of my Add/Edit screens to allow searching for and then selecting a user?

    Alternatively, I guess I could create a Web API controller as part of the project and provide a method for searching for users based on a given search term.  This would then be used by a custom control with some type of autocomplete/typehead functionality.

    What I am really looking for is the easiest way to do this, as I can see need to do this over and over again for many LightSwitch projects.

    Thanks for any advice,
    Richard

    Thursday, May 16, 2013 1:16 AM

Answers

  • In the VS2013 release of LightSwitch they now include a People Picker control if you have an app connected to SharePoint (for example, as a SharePoint-hosted app or something that will be deployed to O365).

    If it is not connected to SharePoint in some way you can choose the People type when defining your model, but you get no built-in control and you have to do it yourself.

    I my unique situation, I did have an on-premisis SharePoint environment but because we have a Mac fleet, I could not use a SharePoint connected app (as this falls back to using NTLM authentication, and therefore breaks Kerberos based single-sign-on required with the Macs).

    So I hooked up to the SharePoint UserInformationList (sort-of-hidden) table on our SharePoint intranet as a source users to use in LightSwitch (as an OData source).

    I then created a query that allowed me to search over first or last name. I added a pre-processes query in code to limit the returned results to 10.

    On my screen I created a popup that contained the list representing the UserInformationList table query, and a text box connected to the search term above this. I then added my Person field to the page and made it a custom control that would show the words "Select..." underlined which the user could click. This was setup with jQuery, so that on the click it would show the popup.

    The user searched for the user, and then when they did so and clicked on a user in the search results it set the model accordingly, which would set the name of the person on the screen (via binding and so on) and close the popup. If I had a number of pickers required on the page, an additional pre-step was to set a screen-local field to remember what person field in my model I wanted to update, so when I chose the person in my popup I knew which model field required updating.

    There was probably a smarter way to do all of this, but I had some time constraints and could not find any overall guide to provide a better solution.

    (Sorry for the long-winded explanation). Anyway, this and a number of other idiosyncrasies with LightSwitch, because I did not have the ideal deployment situation (SharePoint auto hosted or O365) made me go back to ASP.NET MVC.

    I hope this helps,
    Richard

    Tuesday, December 10, 2013 10:30 PM

All replies


  • LightSwitch natively supports datasource connections to SQL, OData, SharePoint lists, and WCF RIA services.  WebAPI (or ADO.NET or other WCF services, etc.) are possible but necessary only if the standard datasource connections above would not suffice.

    For selecting from an entity collection, the HTML client natively uses lists, tiles, or modal window pickers, depending on context.  The easiest way would be to use the built-in UI LightSwitch provides, but really any of the UI controls can be individually customized with JavaScript.

    Thursday, May 16, 2013 5:53 AM
  • The key, then, to using built-in UI then would be the availability of a data source that would allow me to query Active Directory.

    I was hoping that our SharePoint environment might have provided some sort of service I could query to get user information from, but I have not found anything compatible with LightSwitch.

    At the moment I am heading down the path of creating my own Web API method to query AD, and using a custom control to select the user searched for.

    Thanks,
    Richard

    Thursday, May 16, 2013 5:58 AM
  • Hi,

    I have to do the same for my application on HTML Client.

    Could you give me any advice?

    Thanks!

    Tuesday, December 10, 2013 9:40 AM
  • In the VS2013 release of LightSwitch they now include a People Picker control if you have an app connected to SharePoint (for example, as a SharePoint-hosted app or something that will be deployed to O365).

    If it is not connected to SharePoint in some way you can choose the People type when defining your model, but you get no built-in control and you have to do it yourself.

    I my unique situation, I did have an on-premisis SharePoint environment but because we have a Mac fleet, I could not use a SharePoint connected app (as this falls back to using NTLM authentication, and therefore breaks Kerberos based single-sign-on required with the Macs).

    So I hooked up to the SharePoint UserInformationList (sort-of-hidden) table on our SharePoint intranet as a source users to use in LightSwitch (as an OData source).

    I then created a query that allowed me to search over first or last name. I added a pre-processes query in code to limit the returned results to 10.

    On my screen I created a popup that contained the list representing the UserInformationList table query, and a text box connected to the search term above this. I then added my Person field to the page and made it a custom control that would show the words "Select..." underlined which the user could click. This was setup with jQuery, so that on the click it would show the popup.

    The user searched for the user, and then when they did so and clicked on a user in the search results it set the model accordingly, which would set the name of the person on the screen (via binding and so on) and close the popup. If I had a number of pickers required on the page, an additional pre-step was to set a screen-local field to remember what person field in my model I wanted to update, so when I chose the person in my popup I knew which model field required updating.

    There was probably a smarter way to do all of this, but I had some time constraints and could not find any overall guide to provide a better solution.

    (Sorry for the long-winded explanation). Anyway, this and a number of other idiosyncrasies with LightSwitch, because I did not have the ideal deployment situation (SharePoint auto hosted or O365) made me go back to ASP.NET MVC.

    I hope this helps,
    Richard

    Tuesday, December 10, 2013 10:30 PM
  • Thanks a lot for your answer!

    It seems to be more complecated than I thought, I'll try it in the future, for the moment it's not prioritary on my application, and I think I have to learn more of lightswitch to make it well.

    Thursday, December 12, 2013 7:48 AM