Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

Posted on by Microsoft Employee

Hi,

When we created a Pre/Post image, we typically select all attributes to be included. There's a performance hit.

I compiled a list of which attributes should be passed in for the particular image under the plugin step (create sync, create async, update, delete, etc,.)

Some of the images need to include 25+ attributes. I do not want to go through and check those attributes one by one. Please suggest a way to accomplish this task via CRM SDK if I defined attribute schema names.

Our setup:

  • Registration tool: 2011 (Does 2013 or higher include a way to search for attributes? Right now I can only sort alpha asc/desc)
  • Environment: CRM 2013 SP1

XrmToolBox tools to help with CRM Plugin development:

  • Plugin Registration
  • Innofactor Tools > Steps Manipulator
  • Innofactor Tools > Version Verifier

Please let me know if you use any other XrmToolBox tools or otherwise to help with plugin registration/step creation/image creation/image attribute selection.

Thank you for taking your time to answer this. Let me know if I can elaborate further on my request. Please answer the 2 questions in bold so that I can select your answer as the best one.

*This post is locked for comments

  • Josh J A Profile Picture
    Josh J A 50 on at
    RE: CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

    [quote user=""Francesco"][/quote]

    In every plugin where i need to deal to pre-post images i simply call a query to retrieve the full or partial entity, 

    I don't think you are grasping the power of Images.  Most the time I will write a plugin over a custom workflow activity so that I can see what the record was before the change.  Let say I have 5 statuses for a single state and I need to treat the situation of transitioning from status 2 to 3 different from the transition from 1 to 2.  I can get the pre-image and compare it next to the post-image (or the target) to see how to handle it.  There are also ways to cause an Update plugin to fire without the field really changing.  Sometimes you might need to check to make sure it really changed and even though the Target shows the field as having changed you won't know without the pre-image.

    As far as I have seen the difference between grabbing a whole image vs a partial image is very small and most the time not even noticeable.   I tested this with an entity that had >300 fields, using the plugin trace log, I couldn't see a difference between grabbing 5 fields vs all attributes. 

    To answer your question which has already been answered I have not seen a tool that can take a list of field names and add the attributes to the registered image but the XrmToolkit might have something.  

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

    Basically the combination of both answers above would give you the results that you are looking for:

    The following will give you the results of the Post-Execution

    Entity changed = context.InputParameters["Target"]

    or

    Entity allAttributes = service.Retrieve(entityName, entityId, new ColumnSet(true));

    To get the Pre-Execution, you can either use Pre-Image or you can create a plugin step that runs in Pre-Execution and gets the list of all changed fields which can be passed to post-execution.

    This is done by using the context.SharedVariables functions.

    You have a few different options here to get the input parameters and check/compare them in the Post Execution step.

    The logic to use is up to you. Always there are different options for the same task.

  • Suggested answer
    Nuno Profile Picture
    Nuno 2,005 on at
    RE: CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

    Hi Anatoly,

    The Target entity accessible in Input Parameters contains in its attributes collection only the attributes which are being changed.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

    Francesco, thanks for the reply!

    I have no problem with using a SDK retrieve for post image, but if I want to get the pre-image for value comparisons, I won't be able to with retrieve.

    How do you know if the owner of the record changed. What about a dollar value? (If the logic requires these kind of comparisons.

    Thanks!

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Plugins - Use CRM SDK to set which attributes available via Pre/Post Image

    Hi Anatoliy,

    like you, i dont link Pre and Post Image.

    In every plugin where i need to deal to pre-post images i simply call a query to retrieve the full or partial entity, like:

    Entity fullentity = service.Retrieve(entityFromTarget.LogicalName, entityFromTarget.Id, new ColumnSet(true /*or fields i need*/));

    It may seems a "performance miner", however is:

    - clear

    - flexible

    - fast to implement and modify

    - fast to search (no-headache when you deal with missing fields ...)

    Hope it helps!

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans