Only trigger an "if" if specific field is changed on Sales Order RRS feed

  • Question

  • Hi,

    I'm looking to construct an "if" sentence to run, only if a specific field ("customerid") is changed.

    Ie. if the "Name" of the sales order or "Price List" is changed, the "if" shouldn't run.

    I already have some filtering attributes on the plugin, to only run the plugin if certain fields is changed on the Sales Order (Total Amount, customerid, Shipping Method, and a few others)

    I'm running my plugin as PostOperation. 

    Wednesday, November 5, 2014 1:17 PM


All replies

  • You should be able to determine this by checking if the customerid attribute is in the Target InputParameter, as it should only be present if it is has changed.

    However, there are a couple of things to watch for:

    • customerid is a special type of attribute, which maps to either a contactid or accountid. Depending on the plugin stage, the attribute may be present as contactid or accounted, so also check for them
    • CRM will only compare the previous and the new value for changes made in a form. So if, for example, a  used creates a workflow that updates the record and sets the customerid to the same value as it is currently, the customerid attribute will be in the Target InputParameter. If you need to compare the previous and new values, then register a PreImage to get the previous value in the plugin

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

    Thursday, November 6, 2014 11:03 AM
  • Thanks!

    I'm already using pre- and postimage to update the "old" and "new" Account(s) on the SalesOrder, so that should be fine.

    I however cleary see your point on the Account/Contact validation, hence the plugin should actually only run if an Account is in the Customer-field.

    Can you give a hint, on how to look if the customerid is an Account or Contact? :)

    Thursday, November 6, 2014 1:36 PM
  • Hi,

    I can't verify this atm but the Entityreference customerid ought to have a logicalname as one of the attributes and that will be set to contact or account (or perhaps lead).


    Rickard Norström Developer CRM-Konsulterna
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    • Marked as answer by M.Jeppesen Friday, November 7, 2014 6:39 AM
    Thursday, November 6, 2014 2:00 PM
  • Thanks alot!
    That helped :)


    if (customerid.LogicalName == "account")




    Friday, November 7, 2014 6:39 AM