Hello,
We have an entity that we don't want users to manually create or edit records on. The records are created and updated via plugin. I was under the impression that if the plugin is set to "Run In Users Context" set to "System" for example, I can create/edit these records via the plugin - the records will then have the created/modified by value set to the system user, but the delegate fields set to the users initiating the plugin.
This doesn't seem to be the case however. Whilst the records are created and updated OK, the delegate fields are only ever blank. I've tried creating the OrganisationService with the various caller, initiating user IDs and so on. In terms of results, it's as you would expect - if the service is created using the system account, the records are created and updated OK but setting it to the initiating user throws an error that the user doesn't have privileges to perform the action. However in no scenario do these fields get populated.
Have I misunderstood the delegate/on behalf fields? I've read that the above is what they should do, but maybe that was misinformation!
Cheers
P.s. the link below shows what I was expecting, but it's just not doing this - and if it's of any use, we are using XrmToolKit, though I don't think that would make any difference. But here is the organisation service code it uses:
this.OrganizationService = this.ServiceFactory.CreateOrganizationService(this.PluginExecutionContext.UserId);
community.dynamics.com/.../modified-by-delegate-created-by-delegate-in-d365