plug-in triggered in opportunity Close As Won button RRS feed

  • Question

  • hi. i created a plug-in. i want it to be only executed when user clicked Close As Won button.

    I can open trigger the plugin using Message Update and filtering attribute = status code to trigger the plug in.

    However, it triggered also when user clicked Close As Lost and Reopen opportunity.

    i am using pre-operation . when user clicked Close As Won or Close As Lost, the statuscode is not the Won/Lost status (it means that the plugin is triggered before the form status changed. thus i cannot control it in the code.

    consequently, how can i trigger a plug-in only when user clicked Close As Won button.



    Monday, March 19, 2012 3:24 AM


All replies

  • The Opportunity entity handles two additional messages, Win and Lose.

    --pogo (pat) @ pogo69.wordpress.com

    • Marked as answer by verystupidguy Monday, March 19, 2012 5:01 AM
    Monday, March 19, 2012 3:42 AM
  • hi, thanks for the answer.

    i found the messages. and i tested those message can trigger the plug in during Close As Won/ Close As Lost.

    however, if i changed the message to Win. the plugin contained error because

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) is false <<<

    it means i dont know how to get my opportunity id as i just knew i can get the opportunity id by this line

    entity = (Entity)context.InputParameters["Target"]; (it caused error as context doesn't contain inputparameters["target"])

    can you tell me how i can get the opportuniy id ( or other values if possible, although i can receive them after i got the opportunity id) or any articles talks about this?



    Monday, March 19, 2012 3:55 AM
  • Yes, the Target InputParameter is valid for Update and Create messages, but not for Win.

    Instead, try:

    Entity opportunityClose = (Entity)context.InputParameters["OpportunityClose"];
    OptionSetValue status = (OptionSetValue)context.InputParameters["Status"];

    This is documented in the CRM SDK:


    --pogo (pat) @ pogo69.wordpress.com

    Monday, March 19, 2012 4:07 AM
  • thanks . it worked :)


    Monday, March 19, 2012 5:01 AM