Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin on "create" message - how to tell if import?

(0) ShareShare
ReportReport
Posted on by 3,079

We have a plugin that runs on the Create message.  However, we don't want it to run if the records are being created via an import.  Is there any way to tell this without creating a special field to flag imports?  (I worry about that in terms of future maintenance, since things break if that field is removed, accidentally not used on future imports, etc...)

I've seen references to using the context.depth property, but unfortunately the non-import record creations are often called from workflows, and so that depth is not a definitive indicator.

*This post is locked for comments

  • Suggested answer
    PhuocLV Profile Picture
    PhuocLV 347 on at
    Plugin on "create" message - how to tell if import?
    Check target contains field ImportSequenceNumber 
     
    If yes, the record created by Import
     
    Hope this help.
     
    Thank.
  • awalters Profile Picture
    awalters 3,079 on at
    RE: Plugin on "create" message - how to tell if import?

    There are other scenarios where the depth could equal 2, though, like being called from a child workflow.  It's not a guarantee of being an import based on that alone.

  • Mohammed Fakhri Profile Picture
    Mohammed Fakhri 402 on at
    RE: Plugin on "create" message - how to tell if import?

    context.Depth property is equal to 2 instead of 1, when record is created via the out of the box import process in Dynamics 365 Online.

  • Verified answer
    Jonas Rapp Profile Picture
    Jonas Rapp 536 on at
    RE: Plugin on "create" message - how to tell if import?

    Not much of a better solution, but if you feel you have more control of the UI/forms, you could use this custom field to set a value from the UI, rather than setting it during the import.

    So "no value" would mean don't run plugin, where a "known set value" would mean it was intentionally set by deliberate form logic, and the plugin should run.

    Many times we end up with an attribute called "Action Verb", passing information from UI / integration / portal to the plugin to instruct the plugin how to behave.

    In my opinion, at least a little better if you don't really trust future development of integrations :)

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Plugin on "create" message - how to tell if import?

    It seems like half the questions I ask end up having the answer of "no".   :-(  Ah well - guess I'll have to implement yet another hack-y feeling workaround.  Thanks anyway!

  • Verified answer
    Aric Levin Profile Picture
    Aric Levin 30,188 Moderator on at
    RE: Plugin on "create" message - how to tell if import?

    Allison,

    I understood your question. When you run imports that are external to CRM (using SSIS for example), you can use the Import Sequence Number field, but that is also populated by the process/user. If you are using the out of the box import process, I don't think there is anyway to determine during record creation if it was from Import, Form or Workflow.

    I think this was possible in CRM 4.

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Plugin on "create" message - how to tell if import?

    As I mentioned, I'd really prefer not to do it by field, since that's potentially error-prone -

    future imports forgetting/not knowing to use it, etc...  But since we can't rely on the depth or the user in this case as suggested above (the same user will be doing imports as running the workflow at least some of the time), is that type of flag field literally the only option?  Is there really not any indicator in the execution context or anywhere else that definitively determines whether or not it's an import?

  • Aric Levin Profile Picture
    Aric Levin 30,188 Moderator on at
    RE: Plugin on "create" message - how to tell if import?

    Hi Allison,

    There are a few different ways, to achieve this.

    The first as you mention is checking the depth which should be 3 during import, but that might create issues with your workflow.

    One of the options that we usually use is add a custom field to the entity that gets populated during import only. In you plugin you can add a filtering attribute to your plugin, so that it only executed when that field is populated.

    The field should not be visible on the form so that it is not removed.

    If you have an update plugin as well, you should validate if the field value has changed and accommodate to whether or not you need to do changes during the Update.

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: Plugin on "create" message - how to tell if import?

    Hi Allison,

    You cannot 'disable' the plugin for import of data by any configuration, the plugin will trigger.

    However in your plugin code you can add condition to exit the execution.

    Adding a field is one of the way.

    If the import are happening only by specific roles/user then you can add condition of those in the plugin too.

    Depth is not a secure way as the future development might invalidate the check of depth.

    Thanks,

    Prateek

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans