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)

Any tutorials on the update plug-in?

(0) ShareShare
ReportReport
Posted on by

Hello,

I am trying to create an update plug-in but  I am very confused about the  "Filtering Atttributes" nad the "Pre Image".

Do you know where can I find a Video tutorial or an article teaching update-plugin?

Thank you

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Bruno Lucas Profile Picture
    5,421 on at
  • Suggested answer
    Bruno Lucas Profile Picture
    5,421 on at

    You can also download the sdk that has awesome detailed explanations + sample code

    www.microsoft.com/.../details.aspx

  • Verified answer
    PS Profile Picture
    23,577 on at
  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    Hi The Happy Giraff..

    For filtering attributes, here are the links you can see:

    aileengusni.blogspot.com/.../crm-2011-2013-mastering-plugin.html

    crmbusiness.wordpress.com/.../crm-2013-step-by-step-update-plugin-tutorial-using-the-crm-2013-development-toolkit

    mscrmshop.blogspot.com/.../use-of-filtering-attributes-during.html

    andz88.wordpress.com/.../set-filter-attributes-update-plugin-dynamics-crm-2013-upgrade-gotcha

    And for the images here:

    inogic.com/.../pre-image-post-image-explained

    crmbook.powerobjects.com/.../plug-in-images-pre-vs-post

    Here is also overview tip for plugin written very well here:

    www.slideshare.net/.../melbourne-crmug-oct-2014-just1-tip-slides

    Basically the concept of Filtering Attributes is you want the plugin only be executed if only set of fields (attributes) are changed, otherwise the plugin wont be executed, this is the simple words and concept of it without seeing the links.

    So, let's say you have a plugin on update account that has long running time.

    But, in fact it's only affected if an address field is changed, otherwise you no need this logic.

    So, you can filter the attribute on this plugin.

    For the Pre-Image..

    Basic concept here is let's say you have account entity plugin.

    Then, your original value is like this:

    Name = The Happy Giraff Corp

    Website = www.thehappygiraff.com

    Employee size = 100

    Level = Platinum

    Now, you change the employee size to 50

    Here, in your plugin, you want to check the Level.

    So means that if Level = Platinum, the Account employee size cannot be less than 100, it must be something wrong with the new input, you need the validation.

    So that in the plugin, as we know, we have input parameter as current target entity context.

    You want to check if Level == Platinum, then check current employee size.

    So in this context, currently:

    you cannot use entity["new_level"] and it will return null, because what? Because you didn't change any Level, right? The only value you changed is only Employee Size, which is 100 to 50, for the Level, it is still Platinum.

    What you need to do is you should use preImage to get the ORIGINAL VALUE of the LEVEL field.

    So that, you need preimage, then you can have this code:

    preImageEntity["new_level"]

    So that you can use PostImage or PreImage as well for the Level since they are same value.

    As addition in my explanation, I explain as well the PostImage for better understanding.

    For the employee size you will have different value:

    current entity =  50

    preimage = 100

    postimage = 50

    What about Level?

    current entity = NULL

    preimage = Platinum

    and postimage = Platinum.

    I hope this can help you.

    Thank you.

  • Community Member Profile Picture
    on at
    "system.nullreferenceexception object reference not set to an instance of an object"

    I think I've encountered this error before and I tried to debug the code to find the preImage is null. Why and when will the preImage be null?


    protected void ExecutePreOpportunityOwnershipUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null; // TODO: Implement your custom Plug-in business logic. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity target = (Entity)context.InputParameters["Target"]; //Est Revenue Money new_estrevenue = null; if(target.Attributes.Contains("new_estrevenue")) new_estrevenue = (Money)target.Attributes["new_estrevenue"]; else new_estrevenue = (Money)preImageEntity.Attributes["new_estrevenue"]; //Actual Revenue Money new_actualrevenue = null; if (target.Attributes.Contains("new_actualrevenue")) new_actualrevenue = (Money)target.Attributes["new_actualrevenue"]; else new_actualrevenue = (Money)preImageEntity.Attributes["new_actualrevenue"]; //Revenue Percentage Decimal new_revenuepercentage = 0; if (target.Attributes.Contains("new_revenuepercentage")) new_revenuepercentage = Convert.ToDecimal(target.Attributes["new_revenuepercentage"]); else new_revenuepercentage = Convert.ToDecimal(preImageEntity.Attributes["new_revenuepercentage"]); //Est Revenue by Owner Money new_estrevenueforowner = new Money(new_revenuepercentage * new_estrevenue.Value); //Actual Revenue by Owner Money new_actualrevenuebyowner = new Money(new_revenuepercentage * new_actualrevenue.Value); target.Attributes.Add("new_estrevenueforowner", new_estrevenueforowner); target.Attributes.Add("new_actualrevenuebyowner", new_actualrevenuebyowner); } }

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Happy Giraff,

    Have you registered the preimage?

    Go to the step and register new preimage with the same alias you are using.

    Let'say in the code you are using preImageAlias, also need this name registered in the step.

    Anyway, I encountered before after I register it even when I debug I got null for this..

    But, only when I debug it.

    In fact, I got another  error for this not only for this image.

    You can try first using throw new InvalidPluginException (message) method instead of debug it.

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