如何检查事件实体的状态码,如果状态码为1或3,则执行if方法。状态码是一个选项集值,所以我不确定如何在if语句中传递它。
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>();
// var incident = service.Retrieve("incident", detail.IncidentId.Value, new Microsoft.Xrm.Sdk.Query.ColumnSet(true)).ToEntity<Incident>();
if (detail.StatusCode== new OptionSetValue(1) || detail.StatusCode == new OptionSetValue(3))
{
if (sec != null)
{
ExecuteWorkflowRequest request = new ExecuteWorkflowRequest()
答案 0 :(得分:2)
OptionSetValue是整数。这应该起作用。
int statusCode = detail.GetAttributeValue<OptionSetValue>("statuscode").Value;
if(statusCode == 1 || statusCode == 3)
{
}
答案 1 :(得分:1)
您可以这样做:
OptionSetValue localTempVariable;
localTempVariable = new_myEntity.GetAttributeValue<OptionSetValue>("new_myOptionSetAttribute");
通过这种方式,您可以检查 null ,然后访问localTempVariable.Value
(整数)。如下所示:
localTempVariable = new_myEntity.GetAttributeValue<OptionSetValue>("new_myOptionSetAttribute") == null ?