CRM 2011 PLUGIN - PostTaskSetState

I create a plugin when the user sets the task status in crm, checks all tasks related to the incident. If there are no assignments, the incident should be closed.

When I use a profile to debug a plugin, it works fine, but otherwise nothing happens.

IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; EntityReference entity = (EntityReference)context.InputParameters["EntityMoniker"]; ColumnSet cols = new ColumnSet(); cols.AllColumns = true; Entity entityComplete = service.Retrieve("task", entity.Id, cols); if (((OptionSetValue)entityComplete.Attributes["statecode"]).Value == 0) //se o status for cancelado ou concluΓ­do { if (entityComplete.Attributes.Keys.Contains("regardingobjectid") && ((EntityReference)entityComplete.Attributes["regardingobjectid"]).LogicalName == "incident") { QueryExpression query = new QueryExpression(); query.EntityName = "task"; query.ColumnSet = cols; query.LinkEntities.Add(new LinkEntity("task", "incident", "regardingobjectid", "incidentid", JoinOperator.Inner)); query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0)); query.Criteria.AddCondition(new ConditionExpression("activityid", ConditionOperator.NotEqual, entityComplete.Id)); query.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, ((EntityReference)entityComplete.Attributes["regardingobjectid"]).Id)); EntityCollection collection = service.RetrieveMultiple(query); if (collection.Entities.Count == 0) { Entity incident = service.Retrieve("incident", ((EntityReference)entityComplete.Attributes["regardingobjectid"]).Id, cols); SetStateRequest setState = new SetStateRequest(); setState.EntityMoniker = new EntityReference(); setState.EntityMoniker.Id = incident.Id; setState.EntityMoniker.LogicalName = incident.LogicalName; setState.State = new OptionSetValue(1); SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState); } } } 

Can anybody help me? Thanks.

+4
source share
1 answer

Try registering your plugin for the SetStateDynamicEntity message, in addition to the same as for SetState . In my experience, entities must be registered as for work, although I am not 100% clear if this is necessary, I know that this works. A few searches did not give me a definitive answer. Check out this popular CRM blog with the same offer. http://nishantrana.wordpress.com/2010/01/29/plug-in-for-setstate-and-setstatedynamicentity-messages/

I know that with entities I worked with, without registering for SetStateDynamic, it will cause the plugin to not start.

+1
source

Source: https://habr.com/ru/post/1490779/


All Articles