我正在創建一個插件,當用戶在crm中設置任務的狀態時,驗證與事件相關的所有任務。如果沒有開啓任務,則應關閉事件。CRM 2011插件 - PostTaskSetState
當我使用配置文件來調試插件時,它工作正常,但沒有任何反應。
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);
}
}
}
有人能幫助我嗎? 謝謝。
所以只需要連接調試器就可以正常工作? – Daryl
是的,工作正常。 –
您是否在跟蹤日誌中收到任何錯誤?也許爲了調試,如果在調試器中,它作爲一個不同的用戶運行? – Daryl