locked
Fire plugin on case resolution RRS feed

  • Question

  • I'm trying to trigger a plugin on Case Resolution (statecode 1) - below is the plugin code. What I am stumped with here is that for statecodes 0 & 2 (active/deactivated) the code block below works. I have also set it to fire on "SetStateDynamicEntity" It doesn't work when the case has been resolved. Does anyone know why?

    if (state.Value == 1)
                {
                        ///Query expression to retrieve related Contact associated to Account.
                        QueryExpression contact = new QueryExpression { EntityName = "contact", ColumnSet = new ColumnSet("contactid", "incidentid") };
                        contact.Criteria.AddCondition("incidentid", ConditionOperator.Equal, Account.Id);
     
                        //Check weather statecode of the record are Active
                        contact.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
                        EntityCollection Retrievecontact = service.RetrieveMultiple(contact);
     
                        if (Retrievecontact.Entities.Count > 0)
                        {
     
                            foreach (var a in Retrievecontact.Entities)
                            {
                                SetStateRequest contactsetStateReq = new SetStateRequest();
                                contactsetStateReq.EntityMoniker = new EntityReference(a.LogicalName, new Guid(a.Id.ToString()));
                                contactsetStateReq.State = new OptionSetValue(1);
                                contactsetStateReq.Status = new OptionSetValue(-1);
                                service.Execute(contactsetStateReq);
                            }
     
                        }
     
                    }
        #endregion

    Thursday, December 12, 2013 6:48 PM

All replies

  • Register your plugin on the "Close" message to trigger it on Case resolution.

    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    Thursday, December 12, 2013 7:18 PM
  • I'm getting a Plugin Error based on this. I've tried Post-Operation, should it be Pre?
    Thursday, December 12, 2013 7:38 PM
  • you can register plugin on the "Create" message on "incidentresolution" entity, this works when resolving a case.

    Thursday, December 12, 2013 7:48 PM
  • Try also using the Update Event on Case/Incident entity, because actually there are two fields updated, statecode and statuscode.

    Hope it helps!

    Saturday, May 10, 2014 8:06 PM