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)

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

I have the same question (0)
  • prt33k Profile Picture
    6,907 on at

    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

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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.

  • awalters Profile Picture
    3,079 on at

    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?

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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
    3,079 on at

    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
    Jonas Rapp Profile Picture
    536 on at

    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 :)

  • Mohammed Fakhri Profile Picture
    402 on at

    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.

  • awalters Profile Picture
    3,079 on at

    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.

  • Suggested answer
    PhuocLV Profile Picture
    347 on at
    Check target contains field ImportSequenceNumber 
     
    If yes, the record created by Import
     
    Hope this help.
     
    Thank.

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