locked
Filter Search by Logged On User RRS feed

  • Question

  • Hi guys--getting down to the wire on a project and just can't figure out why my scenario does not work... I've seen several similar threads but they haven't gotten me there yet.  First Lightswitch Project btw so be gentle with me :)

    Anyway--the applications default screen is a search screen where I would like to return only requests assigned to the current logged on user.  The 'requests' table has an assigned user selected via an FK to my User Table (just the user ID stored in the 'request' table.  I've created a query (below) on the 'request' table that filters based on 'User.DomainUserID' being equal to a string variable 'DomainUserID'.  I was smart enough to figure out that I needed a field on my User table to hold the windows auth ID (DOMAIN\XXX) to reference.

    Created a search screen based on the query (below) and I set the query parameter to the screen parameter created (ServiceDetailDomainUserID) and set the screen parameter value in  the initializedataworkspace method thusly: 

    Me.ServiceDetailDomainUserID = Me.Application.User.Name.ToString()

    I'm not yet deployed (issue?) so I added the correct current DomainUserID to a record in my user table and assigned records to that User.  When I run in debug a messagebox confirms that my variable containing current logged on user is being set correctly and my User table has a match in it's 'DomainUserID' field and there are records assigned to this User...but they do NOT show up in the search screen.  What gives?!?  I'm totally open to the fact that I may be doing something entirely wrong as I've been banging my head for a while on this one but any help would be greatly appreciated as I'm running out of time..  THanks!

    -Bob

    Query:

    Screen:

    Monday, July 9, 2012 5:27 PM

Answers

  • Check the forward slash versus the backslash. I think that's what's causing the match to fail.
    • Marked as answer by rz1224 Monday, July 9, 2012 7:31 PM
    Monday, July 9, 2012 7:10 PM

All replies

  • Need a little clarification. You say:

    "I'm not yet deployed (issue?) so I added the correct current DomainUserID to a record in my user table and assigned records to that User.  When I run in debug a messagebox confirms that my variable containing current logged on user is being set correctly and my User table has a match in it's 'DomainUserID' field and there are records assigned to this User"

    Do you mean you haven't published your app yet? If so then the only user you're going to get by

    Me.Application.User.Name.ToString()

    is TestUser. So you've set up a DomainUserID called TestUser, is that correct?

    And what is 'User.DomainUserID'? Is that just a typo and you meant to say IMAUser.DomainUserID?

    Monday, July 9, 2012 5:44 PM
  • Thanks for the reply Kyle-- 

    To clarify--No I have not published the app, however the code:  "ShowMessageBox(Application.User.Name)" does return the correct user logged into the machine (IMA_W\administrator in my case) and I do have a User in the IMAUsers table with a DomainUserID of 'IMA_W\administrator'.  Should that not happen?...

    Any you're correct I did mean IMAUser.DomainUserID.

    Monday, July 9, 2012 6:13 PM
  • I'm using Forms Authentication, not Windows Authentication. But I was under the impression that before you Publish an app, the only user you have to work with is a special one created by Lightswitch called TestUser. Now I'm wondering if Windows Authentication behaves differently. Hopefully someone else can chime in with a more definitive answer.

    But onto the larger problem at hand. Your message box says your User Name is administrator and I have no reason to doubt it. So why isn't your filter query returning anything?

    How about trying to go to Add Data Item and adding the whole table as a Query. So below your filtered grid is another grid that is completely unfiltered and has all the entries. Keep your message box or better yet just add a Local Property in the form of a string and assign it to Me.Application.User.Name.ToString() in _InitializeDataWorkspace() and place it somewhere on the screen. That way you constantly have the User Name displayed and you can check it against what is in the full grid to see if they do indeed match. A screen shot of that would be great.

    Monday, July 9, 2012 6:27 PM
  • Thanks Kyle--Thanks--screenshot below.  Just to be clear, IMAUser.DomainUserID does not appear directly in the searched table.  IMAUsers is linked to it as a FK, UserID is stored in the requests table, User Name (Not DomainID) is displayed on the screen.  If you look back at my query I extended IMAUser to include IMAUser.DomainUserID in the filter.  Added 'other screen data' just to show the field in whole table query.

    Monday, July 9, 2012 7:03 PM
  • Check the forward slash versus the backslash. I think that's what's causing the match to fail.
    • Marked as answer by rz1224 Monday, July 9, 2012 7:31 PM
    Monday, July 9, 2012 7:10 PM
  • I'm SUCH an idiot!  I can't tell you how many times I stared at that and never noticed.  Thanks so much for your help, hope I didn't distract you from anything important.
    Monday, July 9, 2012 7:30 PM
  • No worries. After staring at a problem for so long we all become blind to the little details. These forums are a great place to find another set of eyes. Good luck!
    Monday, July 9, 2012 7:32 PM