web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get username inside a update plugin

(0) ShareShare
ReportReport
Posted on by 437

Hi Folks , 

Please help me to find the username inside a update plugin.

Entity entity = (Entity)context.InputParameters["Target"];
Entity opp = new Entity("acc");
acc.Id = entity.Id;

acc.Attributes["new_loggedIn"] = context.UserId;

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    You can get user's id from context.UserId. The next step is to retrieve the name using endpoint:

    var username = service.Retrieve("systemuser", context.UserId, new ColumnSet("fullname")).GetAttributeValue<string>("fullname");

  • windyMill Profile Picture
    437 on at

    Hi Andrew ,

    What is service here ?

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    service is the instance of IOrganizationService. In followinf example it is shown how to get it - docs.microsoft.com/.../sample-create-basic-plugin

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    This is OrganizationServiceProxy  -

    Here you go - 

    IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext));

    // Obtain the organization service reference.

    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

  • windyMill Profile Picture
    437 on at

    Thanks , my mistake I didnt see it . Code is working perfectly

  • windyMill Profile Picture
    437 on at

    Thanks Goutam for making it clear.

    I didnt notice service was already in plugin code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans