Webresource Plugin Step Image is the published record? RRS feed

  • Question

  • I'm a little confused over how webresources are published and getting my plugin to detect the proper component state.

    What I want to do:

    We have a webresource js file and from time to time there are changes made to that file. If changes are made the plugin does NOTHING. Once the webresource is published then my plugin parses the js file and adjusts any records etc. as needed.

    I thought a good way to track the componentstate would be to attach an image to my plugin step. The problem is that the image does NOT contain the delta's as I would have expected. Instead it always displays the published record??

    My step is registered:

    • Message: Update
    • Primary Entity: webresource
    • FIlter: All Attributes
    • Exec Order: 1
    • Pipeline: PostOp
    • Exec: Synch.

    My image is a PreImage with all parms. I've tried all sorts of variations with preimage / postimage and step pipeline....all the same.

    So again the preimage ALWAYS matches the published webresource.

    Say I open the js file, make a change, then save it. Update webresource fires and I would have expected the pre-image to contain the new changes...but it doesn't. The image matches / contains all the published record values.

    Moving on from the save I now click the publish button and again the pre-image doesn't contain the unpublished values but instead the published values???

    I would have thought at the very least the image would contain the "content" of the unpublished record but no..it is the content, componentstate...everything matches published record.

    Am I doing / configuring the image / step wrong...or do I just not understand properly how pre & post images work.

    Thank You

    Thursday, July 17, 2014 10:35 PM

All replies

  • I think you've found a limitation with images and plugins. The plugin model was designed mostly for data entities, whereas a web resource is a publishable entity ('data entity' and 'publishable entity' are my terms).

    For publishable entities, CRM stores (at least) 2 instances, the published and the unpublished version. I don't think anything is documented about which version is used in the images, and it looks like from your experience that it's the published version. I don't think there's any way to change this behaviour

    Do you need the previous values ? If not, you can get the unpublished data with a RetrieveUnpublishedRequest

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Friday, July 18, 2014 8:26 AM
  • David,

    Thank you for taking the time to help. So I can indeed...and that is how I ran my test to see what the image was producing...use the RetrieveUnpublishedRequest.  To answer your very pertinent question about needing the previous values...I do not..per se.

    What I am trying to do is analyze the js file (it is a json data file) and make some changes to entity records based upon the information in it.

    If the admin user updates the js file but *DOES NOT* publish I don't want to change anything. If they publish the js file *THEN* I do want to parse and make the changes.

    So far the closest I have come is fire on the Update webresource message...that however fires at three different times and only one of which I actually want to make changes. It fires when:

    1. Editing the js file in text editor and then clicking OK.
    2. Clicking save or save and close
    3. When clicking publish (this is the one time I actually want to read the file and make changes if needed)

    So the purpose of the image was trying to find some way of detecting it was #3.

    I'm going to try and see if running the plugin post-op only has the unpublished js file now published and see if that leads to success.

    Any other thoughts or ideas gladly accepted.

    UPDATE: In refactoring to new approach mentioned above I just realized....I do use the image for one thing..I detect the name of the webresource and exit if it is not the resource we are monitoring for changes.

    UPDATE 2. Nope in post-op "published entity" record still has old information.

    UPDATE 3. Looking at Publish or Publish All plugin messages..not finding much information but perhaps something will turn up.

    • Edited by zzpluralza Friday, July 18, 2014 5:58 PM
    Friday, July 18, 2014 4:59 PM