Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

with different regarding task it gonna change the case status to the same regarding task

(0) ShareShare
ReportReport
Posted on by

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;
}
}


}
}

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    No duplicates, please.

  • Community Member Profile Picture
    on at
    update the case status depend on task regarding status

    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;
            }
  • Community Member Profile Picture
    on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    thansk

  • Suggested answer
    Gowri Halan Profile Picture
    10 on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    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..)).

  • Community Member Profile Picture
    on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    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

  • Community Member Profile Picture
    on at
    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

    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;
    }
    }


    }
    }

  • Community Member Profile Picture
    on at
    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

    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;
    }
    }


    }
    }

  • Gowri Halan Profile Picture
    10 on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    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 ?

  • Community Member Profile Picture
    on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    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

  • Community Member Profile Picture
    on at
    RE: with different regarding task it gonna change the case status to the same regarding task

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Holly Huffman Profile Picture

Holly Huffman 103

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 96 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 51 Most Valuable Professional

Product updates

Dynamics 365 release plans