Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Fire plugin on case resolution

$
0
0

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


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>