我正在Dynamics 365中创建一个插件,目的是当事件实体状态代码设置为1或3时才触发工作流。但是,必须在触发工作流之前的24小时内将状态码设置为1或3。 同样,在执行工作流程之后,状态码应设置为待处理。
我不确定我是否朝正确的方向编码。我不确定该怎么做。如果有人可以告诉我如何解决这种情况。谢谢!
到目前为止,这是我的意思:出于测试目的,触发工作流的时间为10秒。
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
//create an entity
Entity entity = (Entity)context.InputParameters["Target"];
//after creating the entity, we need to retrieve the required entity: Incident
//retrieve incident entity
Incident detail = entity.ToEntity<Incident>();
//contain int value that represents the optionset
TimeSpan sec = new TimeSpan(00,00,10);
// var incident = service.Retrieve("incident", detail.IncidentId.Value, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)).ToEntity<Incident>();
//retrieve the value of status code of a particular entity
//if optionsetvalue is the same for a 24 hr period
if (detail.StatusCode== new OptionSetValue(1) || detail.StatusCode == new OptionSetValue(3))
{
if (sec != null)
{
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
{
WorkflowId = new Guid("DB9ABA7E-D4F9-4EBF-8062-C85EF7B850FB"),
EntityId = detail.Id,
};
ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);
//change it to pending..statuscode
detail.StatusCode = new OptionSetValue(425390002);
}
service.Update(detail);
}
}
答案 0 :(得分:0)