if csu task rejected =>> close case can some one suggest me how to do that
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using System.ServiceModel;
using System.Security.Principal;
using Microsoft.Xrm.Sdk.Query;
namespace taskcheck
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
trace.Trace("optain the tracking service");
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
try
{
//obtain the target entity from the inputparameter
Entity target = (Entity)context.InputParameters["Target"];
//rettrive
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//csutask status change
EntityReference regardingCaseRef = entity["reagardingobjectid"] as EntityReference;
//retrive regarding from the back end
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
//retrive multiple using query expression
QueryExpression qeRelatedTasks = new QueryExpression("task");
qeRelatedTasks.ColumnSet = new ColumnSet(true);
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid",ConditionOperator.Equal,regardingCaseRef.Id));
EntityCollection relatedTasks = service.RetrieveMultiple(qeRelatedTasks);
if (AllTaskReject(relatedTasks))
{
trace.Trace("Case title: " + regardingCase["title"]);
//statuscode
}
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
public bool AllTaskReject(EntityCollection relatedTasks)
{
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190003))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}
}
}
}