locked
fields data during plugin update (pre-operation) RRS feed

  • Question

  • hi, i created a plugin and it is Message = Update and execution in pre-operation.

    i found that it is different from Message = Create and execution in pre-operation.

    as i can retrieve the fields when message = Create in the target parameter. however the update's pre-operation doesn't contain any information of the fields.

    thus, how can i retrieve the changed fields value in  Message = Update and execution in pre-operation ?

    (i know i can change the plugin to post-operation and retrieve the updated record and update it again after processing the retrieved value, but i think it is too much transaction required, i want to update as i trying to update it in the message name=create, and doesn't require to use update service)


    a

    Friday, August 10, 2012 5:22 AM

Answers

  • Hi,

    The Target entity will always contain the values being modified in the current pipeline - irrespective of stage. So you can access the modified values in the Pre-Operation.

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by verystupidguy Monday, October 22, 2012 6:41 AM
    Wednesday, October 17, 2012 7:42 AM
    Answerer

All replies

  • Hi a,

    Within the Pre-Operation Create step you need to look at the Target Image to see the values that are be sent to the database.

    Within the Pre-Operation Update step, you can still use the Target Image to see what values are being updated, but you must also use a registered 'PreEntityImage' to see the values that are already in the database.

    See: http://msdn.microsoft.com/en-us/library/gg309673.aspx

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Proposed as answer by Sam - Inogic Friday, August 10, 2012 9:49 AM
    Friday, August 10, 2012 7:16 AM
    Answerer
  • hi, i did try your approach, i registered the preimage

    and i call it in the plugin by

             Entity pre = context.PostEntityImages["preroomrate"];
             throw new InvalidPluginExecutionException(((OptionSetValue)pre.Attributes["hello"]).Value.ToString());       

    i can receive the value of the field hello however the value is the one which still not updated. for example i changed hello from "you" to "world" so that the plugin is triggered, but the ((OptionSetValue)pre.Attributes["hello"]).Value.ToString() showed "you" but not "world"


    a

    Tuesday, September 11, 2012 9:17 AM
  • Hi,

    The Target image will show what is being updates in the pipeline.

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, September 11, 2012 9:08 PM
    Answerer
  • i cannot say it is not correct

    however i still cannot achieve what i wanted

    by registering a pre-image

    i can read the target value as the modified value now in the pre-operation stage of plugin

    i can also read the previous value by using service.Retrieve.

    however i found that the target only contain the value that is begining modified by not included the other modified value

    for example. a, b ,c are modified, while a plugin is used to sum all of them up as a field value "d", thus the plugin will be triggered when a or b or c is updated

    scenario 1: (correct)

    a= 4   > =5 (update)

    b=4  > =4 (no update)

    c = 4  > =4 (no update)

    then d will be summed up correctly as 13

    scenario 1: (incorrect)

    a= 4   > =5 (update)

    b=4  > =5 (update)

    c = 4  > =5 (update)

    then d will be summed up incorrectly as 13, simply because i cannot the plugin session of "a is updated" doesn't contain the modfieid value of b and c


    a

    Wednesday, September 19, 2012 7:04 AM
  • Hi,

    The PreImages and Target images are not dependant on each other. You will always be able to get the Target image to see what has been updated, but the PreImage you register will show you values before they were updated. To get the most recent values for a,b & c, you need to combine the PreImage and the Target, using the Target value if it exists, otherwise using the PreImage value. You shouldn't use a Retreive to get the values, but instead use the PreImage.

    hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Wednesday, September 19, 2012 1:54 PM
    Answerer
  • yes, but retrieve the modified value is only able to do in post-operation but not pre-operation of plugin pipeline stage.

    initially i intended to implement in pre operation as i dont want call one more update service only.


    a

    Wednesday, October 17, 2012 7:37 AM
  • Hi,

    The Target entity will always contain the values being modified in the current pipeline - irrespective of stage. So you can access the modified values in the Pre-Operation.

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by verystupidguy Monday, October 22, 2012 6:41 AM
    Wednesday, October 17, 2012 7:42 AM
    Answerer