Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

Posted on by Microsoft Employee

Requirement:

To identify if a record CRUD operation was done from Dynamics UI or from Web API at plugin .

 

Solution that worked until now:

By Checking the value of “context.ParentContext.ParentContext” in the plugin we were able to distinguish the source of request (Dynamics UI/ API) 
if value of “context.ParentContext.ParentContext” is null, it meant record was created from UI

If value of “context.ParentContext.ParentContext” is NOT null, we assumed that record was created using API

 

 

Value

Source

context.ParentContext.ParentContext

Null

Dynamics UI

Not Null

Web API

 

But we have now run into another issue after introducing “Business Process Flow” for an entity. Below is the details around the issue.

 

Current Issue:

When a Business process flow is added to an entity. For e.g. Let’s call it “myEntity”. Dynamics creates another inbuilt entity called “myEntity Process” entity which stores the stages.  When a user creates a “myEntity” record , two create requests are fired on plugin, as below:

  1. “myEntity” entity's create event
  2. “myEntity Process” entity's create event 

After the business process flow was added below is the behavior for both the entities.

For create event on “myEntity”, we have different behaviours on different version of dynamics:

  • On 8.2 on-premises – The context.ParentContext.ParentContext object is NULL as expected when a record is created from Dynamics UI.
  • On 9.0 online -  the context.ParentContext.ParentContext object is not NULL when a record is created from Dynamics UI 

For create event on “MyEntity Process” create event the "context.ParentContext.ParentContext" is not NULL for on prem and online instances as well. 

Based on this behavior, we have the below questions.

Questions:

  1. What is a fool proof solution to identify CRUD operations done through web API vs CRUD operations done through Form to prevent the plug-in from executing repeatedly.
  2. Why is there a different in behavior between 8.2 and 9.0 myEntity explained above?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Is there any replacement/substitute for Context.CallerOrigin?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Hi Arun, We can't use createdby, as it is being used to identify the user.

  • Suggested answer
    Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    If you are calling the web api from external platform with some application user, then createdby (callinguser context) can be used to identify.

    Web api allows impersonation, so the application user (non-interactive system user) is the best bet.
  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Agree, for these special entities, you can do something else like append some default text and then track it in plugin. You can also remove the text within the plugin if it is something you don't want.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Yes Ravi, This is a good solution but we can't add flag to all the entities like annotation.

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Having a flag which can be set from the plugin can be a good option, which is not dependent on any changes based on version updates.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How to identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

    Hi,

    Based on the documentation, the parent context "may" contain value. This is not confirmed. So I would not suprise that this has stopped working in v9.0. Ideally the best option to identify the source is to have a field and set the source accordingly and then within the plugin check the source.  This will work for sure in future as well as in this case we are not using any of the internal properties.

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans