locked
Get Userid from User Name RRS feed

  • Question

  • Hi, I need to get the UserID (so I can send an email) but I only have the username.

    For example I have "domain\daren" but I need my userid.  Is there a quick reverse lookup function in C#?

    Thanks Daren

    Friday, March 19, 2010 5:57 AM

Answers

  • ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[]{"systemuserid"};
              
    QueryByAttribute qe = new QueryByAttribute();
    qe.Attributes = new string[] { "domainname" };
    qe.Values = new string[] { "the_user_login_value" };
    qe.ColumnSet = cols;
    qe.EntityName = "systemuser";
    
    BusinessEntityCollection bec = service.RetrieveMultiple(qe);
    
    Guid userId = ((systemuser)bec.BusinessEntities[0]).systemuserid.Value;


    My blog : http://mscrmtools.blogspot.com
    You will find:
    Bulk Delete Launcher(Delete data based on advanced find queries)
    Form Javascript Manager (export/import javascript from forms)
    ISV.Config Manager (graphical ISV.config edition - export/import)
    View Layout replicator (customize one view and replicate to others)
    And others (use tool tag on my blog)
    Friday, March 19, 2010 5:44 PM
    Moderator

All replies

  • you mean systemuserid (the Guid)?.

    well you can query using retrievemultiple. Pass the domainname as condition and get the systemuserid. Then you can use this id to send mail


    - Arvind
    Friday, March 19, 2010 10:03 AM
  • ColumnSet cols = new ColumnSet();
    cols.Attributes = new string[]{"systemuserid"};
              
    QueryByAttribute qe = new QueryByAttribute();
    qe.Attributes = new string[] { "domainname" };
    qe.Values = new string[] { "the_user_login_value" };
    qe.ColumnSet = cols;
    qe.EntityName = "systemuser";
    
    BusinessEntityCollection bec = service.RetrieveMultiple(qe);
    
    Guid userId = ((systemuser)bec.BusinessEntities[0]).systemuserid.Value;


    My blog : http://mscrmtools.blogspot.com
    You will find:
    Bulk Delete Launcher(Delete data based on advanced find queries)
    Form Javascript Manager (export/import javascript from forms)
    ISV.Config Manager (graphical ISV.config edition - export/import)
    View Layout replicator (customize one view and replicate to others)
    And others (use tool tag on my blog)
    Friday, March 19, 2010 5:44 PM
    Moderator