web
You’re offline. This is a read only version of the page.
close
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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans