locked
Working with the Current User in a New Data Screen (C#) RRS feed

  • Question

  • Hello, I have a pretty straightforward requirement I think I haven't found a solution to.  Whenever a New Data Form is opened, I would like to populate the current user (some form of identification) into a field, similar to populating the current date:

    partial void ReviewForm_Created()
            {
                FormProperty.ReviewDate = DateTime.Now;
                FormProperty.FormUsed = "Review";
                FormProperty.Reviewer = ???
    
            }

    What is the syntax to populate the Current User where the ???s are, and are there options for what can be populated easily (like UserName, Display Name, etc)?

    Thursday, June 28, 2012 4:01 PM

Answers

  • Hi

    Here is the code

    if (this.Application.User != null)
                {
                    CreatedBy = this.Application.User.FullName;
                }

    Put it within your created method. Same as you do for current date. You can use full Name and User Name as per your choice.

    Hope this help...

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.


    • Edited by babloo1436 Thursday, June 28, 2012 4:30 PM
    • Marked as answer by Matt Brandt Thursday, June 28, 2012 4:32 PM
    Thursday, June 28, 2012 4:28 PM

All replies

  • Hi

    Here is the code

    if (this.Application.User != null)
                {
                    CreatedBy = this.Application.User.FullName;
                }

    Put it within your created method. Same as you do for current date. You can use full Name and User Name as per your choice.

    Hope this help...

    Regards


    Rashmi Ranjan Panigrahi
    www.lightswitchspecial.com

    If you found this post helpful, please “Vote as Helpful”. If it answered your question, please “Mark as Answer”.
    This will help other users to find their answer quickly.


    • Edited by babloo1436 Thursday, June 28, 2012 4:30 PM
    • Marked as answer by Matt Brandt Thursday, June 28, 2012 4:32 PM
    Thursday, June 28, 2012 4:28 PM
  • Hi Matt,

    Take a look at the User property off of Application.  e.g. this.Application.User  From here you can get the full name and name.  Is that sufficient for your scenario?

    Thursday, June 28, 2012 4:29 PM