Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

how to update case description

Posted on by Microsoft Employee

try
{
Entity target = (Entity)context.InputParameters["target"];
//Inheritance OBJECT

EntityReference regardingCaseRef = target["regardingobjectid"] as EntityReference;
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
QueryExpression qeRelatedTasks = new QueryExpression("incident");

qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef));

EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);

// update case description = all tasks completed

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to update case description

    how do i call the bool

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to update case description

    hi is still not work

    public void Execute(IServiceProvider serviceProvider)

           {

               IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

               ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

               IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               try

               {

                   trace.Trace("Inside try");

                   Entity target = (Entity)context.InputParameters["target"];

                   //Inheritance OBJECT

                   EntityReference regardingCaseRef = target["regardingobjectid"] as EntityReference;

                   Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));

                   QueryExpression qeRelatedTasks = new QueryExpression("incident");

                   qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef));

                   EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);

                   trace.Trace("Case title: " + regardingCase["title"]);

                   // update case description = all tasks completed

                   Entity incident = new Entity("incident")

                   {

                       Id = regardingCaseRef.Id

                   };

                   incident["description"] = "All Task Completed";

                   service.Update(incident);

               }

               catch (Exception ex)

               {

                   throw (ex);

               }

           }

           //get all the task that have regarding = regarding

           //loop thr all task (entitycollection.entities

           //and check if any task that has CSU task status not equal to completed

           //if yes break out of the loop and  return false

           //if no write in the description all task is done

           //If (task.All(x => x.TaskStatus == Task.Cometed)

           // do something here

           public bool AreAllRelatedTasksCompleted(EntityCollection relatedTasks)

           {

               if (relatedTasks.Entities.All(x => ((OptionSetValue)x["cos_csutaskstatus"]).Value == 769190000))

               {

                   //Console.WriteLine("All task completed");

                   return true;

               }

               else

               {

                   return false;

               }

           }

       }

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: how to update case description

    Hi,

    You don't need query expression.

    After service.retrieve you need to add below code to update case description

    Entity incident=new Entity("incident");

    incident.Id= regardingCaseRef.Id;

    incident ["description"]="All Task Completed";

    service.Update(incident);

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: update case description = all tasks completed

    hi i need help on this

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    update case description = all tasks completed


    Entity target = (Entity)context.InputParameters["target"];
    //Inheritance OBJECT

    EntityReference regardingCaseRef = target["regardingobjectid"] as EntityReference;
    Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
    QueryExpression qeRelatedTasks = new QueryExpression("incident");

    qeRelatedTasks.Criteria.AddCondition(new ConditionExpression("regardingobjectid", ConditionOperator.Equal, regardingCaseRef));

    EntityCollection allRelatedTasks = service.RetrieveMultiple(qeRelatedTasks);

    // update case description = all tasks completed
    var entityRef = new Entity(retrieved.Entities.LogicalName, retrieved.Entities.Id);
    entityRef["Description"] = "all tasks completed";
    service.Update(entityRef);

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans