Announcements
this only work for reject. Any one have any idea if you chose others choice it gonna change the case status to that
namespace pluginproject
{
public class TaskCheck : IPlugin
{
//logic call name regarding:regardingobjectid
//csu tasok name cos_csutaskstatus
//if task of a case is completed
//check all the task of the same case
// if all other task are completed too update the descriptions field of the case to all task completed
// Update the Assembly first
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");
try
{
trace.Trace("Inside try");
Entity target = (Entity)context.InputParameters["Target"];
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//Inheritance OBJECT
trace.Trace("check target does have regardingobjectid proprty?");
EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
//chi nhan nhung cot bi thay doi
trace.Trace("1");
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
trace.Trace("2");
QueryExpression qeRelatedTasks = new QueryExpression("task");
trace.Trace("3");
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef.Id));
qeRelatedTasks.ColumnSet = new ColumnSet(true);
trace.Trace("4");
EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);
trace.Trace("check condition");
if (AreAllRelatedTasksCompleted(allRelatedTasks))
{
trace.Trace("Case title: " + regardingCase["title"]);
regardingCase["description"] = "All Task Completed";
service.Update(regardingCase);
}
//var checkComplete = AreAllRelatedTasksCompleted( relatedTasks) ;
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
public bool AreAllRelatedTasksCompleted(EntityCollection relatedTasks)
{
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190000))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}
}
}
}
No duplicates, please.
I have this code below. If all the task is reject =>> the case status=>> reject, but i want if i choose other like approve or sth it it gonna do the same with case status
like i choose csu task status == complete =>> csu case status== complete
it has complete, reject,on hold,pending
Entity target = (Entity)context.InputParameters["target"];
//retrieve
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//pointer
EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
//retrieve 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("status check");
regardingCase["cos_csucasestatus"] = new OptionSetValue(769190006);
trace.Trace("status check 2");
service.Update(regardingCase);
trace.Trace("status check 3");
/* Entity incident = new Entity("incident");
incident.Id = regardingCaseRef.Id;
trace.Trace("1");
incident["cos_csucasestatus"] = new OptionSetValue(769190006);
service.Update(incident);*/
// regardingCase.Attributesk["cos_csucasestatus"] = new OptionSetValue(769190006);
}
}
catch
{
throw;
}
}
}
public bool AllTaskReject(EntityCollection relatedTasks)
{
//check all the the task if rejected continue if on task not rejected do nothing
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190003))
{
return true;
}
else
{
return false;
}
thansk
So if I am not wrong below condition check reject condition ? add one more OR condition for completed status it should work.
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190000))
But looking at your code there are chances for lots of improvement.
1. You dont have to query case entity at all
2. dont add new column(true). only specify required column (new column("statecode","statuscode",etc..)).
yes but now i want it gonna check all task if all task is complete =>> complete
reject=>> reject
this code above can only do reject
this only work for reject. Any one have any idea if you chose others choice it gonna change the case status to that
namespace pluginproject
{
public class TaskCheck : IPlugin
{
//logic call name regarding:regardingobjectid
//csu tasok name cos_csutaskstatus
//if task of a case is completed
//check all the task of the same case
// if all other task are completed too update the descriptions field of the case to all task completed
// Update the Assembly first
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");
try
{
trace.Trace("Inside try");
Entity target = (Entity)context.InputParameters["Target"];
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//Inheritance OBJECT
trace.Trace("check target does have regardingobjectid proprty?");
EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
//chi nhan nhung cot bi thay doi
trace.Trace("1");
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
trace.Trace("2");
QueryExpression qeRelatedTasks = new QueryExpression("task");
trace.Trace("3");
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef.Id));
qeRelatedTasks.ColumnSet = new ColumnSet(true);
trace.Trace("4");
EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);
trace.Trace("check condition");
if (AreAllRelatedTasksCompleted(allRelatedTasks))
{
trace.Trace("Case title: " + regardingCase["title"]);
regardingCase["description"] = "All Task Completed";
service.Update(regardingCase);
}
//var checkComplete = AreAllRelatedTasksCompleted( relatedTasks) ;
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
public bool AreAllRelatedTasksCompleted(EntityCollection relatedTasks)
{
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190000))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}
}
}
}
this only work for reject. Any one have any idea if you chose others choice it gonna change the case status to that
namespace pluginproject
{
public class TaskCheck : IPlugin
{
//logic call name regarding:regardingobjectid
//csu tasok name cos_csutaskstatus
//if task of a case is completed
//check all the task of the same case
// if all other task are completed too update the descriptions field of the case to all task completed
// Update the Assembly first
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");
try
{
trace.Trace("Inside try");
Entity target = (Entity)context.InputParameters["Target"];
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));
//Inheritance OBJECT
trace.Trace("check target does have regardingobjectid proprty?");
EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
//chi nhan nhung cot bi thay doi
trace.Trace("1");
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
trace.Trace("2");
QueryExpression qeRelatedTasks = new QueryExpression("task");
trace.Trace("3");
qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef.Id));
qeRelatedTasks.ColumnSet = new ColumnSet(true);
trace.Trace("4");
EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);
trace.Trace("check condition");
if (AreAllRelatedTasksCompleted(allRelatedTasks))
{
trace.Trace("Case title: " + regardingCase["title"]);
regardingCase["description"] = "All Task Completed";
service.Update(regardingCase);
}
//var checkComplete = AreAllRelatedTasksCompleted( relatedTasks) ;
}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
public bool AreAllRelatedTasksCompleted(EntityCollection relatedTasks)
{
if (relatedTasks.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csutaskstatus")?.Value == 769190000))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}
}
}
}
If I am not wrong your requirement is when an task for a case entity status is updated, then check all the tasks status and if all the tasks are completed, update case entity ?
in the task i have mul choices like reject, approve,etc and in the case i have csucase task with the same choice with task.
so in the code above you can only choose one choices for every case.
i want to each case have diff choice depent on what the user choose in the csutask.
thanks
in the task i have mul choices like reject, approve,etc and in the case i have csucase task with the same choice with task.
so in the code above you can only choose one choices for every case.
i want to each case have diff choice depent on what the user choose in the csutask.
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156