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 :
Customer experience | Sales, Customer Insights,...
Answered

Plugin's InitiatingUserId dilemma

(0) ShareShare
ReportReport
Posted on by 50

Hi everyone,

i'm trying to solve an issue i'm experiencing on a couple of plugins in my client's environment, here's the scenario:

  1. User A creates a record "Interest"

  2. "Interest" creation triggers a plugin running on "SYSTEM (Disabled)" context. InitiatingUserId is User A in this case (everything's fine until now).
    The plugin creates a record "Brand Data".

  3. "Brand Data" creation triggers another plugin, always in "SYSTEM (Disabled)" context. Depth is 2 and InitiatingUserId is SYSTEM in this case.

In point 3 i was expecting that the InitiatingUserId, which the documentation describes as the "user who started the pipeline", would be actually propagated to each plugins' chain level. Also observing plugin ParentContext the value isn't the expected one

  • Actual plugin context: EntityName = "Brand Data", InitiatingUserId = "SYSTEM"
  • Parent plugin context: EntityName = "Interest", InitiatingUserId = "SYSTEM" -> this is against point 2

I thought i understood how InitiatingUserId works, but it's clear i'm missing something.

Can please someone explain the current behaviour of this property and user impersonation in a plugin chain like this?

Thanks in advance,

DT

PS. The environment is a Dynamics 365 v9.1 online.

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hello,

    3rd point where initiating user id is System beacuse you are creating record using Organizationservice which is created using system.

    When you create organizationservice using context.initiatinguserid then you will same user in 3rd point.

    please check your orgnaizationservice object as how you have created in your plugin. Are you passing null value or guid.empty as parameter.

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

    IOrganizationService service = serviceFactory.CreateOrganizationService(null); -- It will take system

    IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); -- It will take same initiating user as point 1

    Please mark my answer verified if i were helpful

  • Daniele.Torlai Profile Picture
    50 on at

    Hi,

    so all i have to do is to set "InitiatingUserId" in serviceFactory.CreateOrganizationService before i create the Brand Data record in the 1st plugin (POINT 2) in order to propagate the user also in the 2nd plugin (POINT 3).

    Did I get it right?

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hey,

    That is correct.

    Please mark my answer verified if i were helpful

  • Daniele.Torlai Profile Picture
    50 on at

    It worked like a charm,

    Thank you so much for pointing me to the right solution.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans