Skip to main content

Notifications

Announcements

No record found.

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

  • windyMill Profile Picture
    437 on at
    RE: How to get username inside a update plugin

    Thanks Goutam for making it clear.

    I didnt notice service was already in plugin code.

  • windyMill Profile Picture
    437 on at
    RE: How to get username inside a update plugin

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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: How to get username inside a update plugin

    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);

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to get username inside a update plugin

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

  • windyMill Profile Picture
    437 on at
    RE: How to get username inside a update plugin

    Hi Andrew ,

    What is service here ?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: How to get username inside a update plugin

    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");

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans