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 identify at plugin, if a record CRUD operation was done from Dynamics UI or from Web API

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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.

  • Community Member Profile Picture
    on at

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

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    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.
  • Community Member Profile Picture
    on at

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

  • Community Member Profile Picture
    on at

    Is there any replacement/substitute for Context.CallerOrigin?

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