Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

update Satisfaction

(0) ShareShare
ReportReport
Posted on by

how can i update the Satisfaction. In the incident case form i have case status 

if the case status = complete 

=>> Satisfaction will be sastisfied

try
{
trace.Trace("insidetry");
Entity incident = (Entity)context.InputParameters["Target"];
Entity entity = service.Retrieve("incident", incident.Id, new ColumnSet(true));
//chi nhan nhung cot bi thay doi
trace.Trace("case");
EntityReference RegardingCaseRef = entity["cos_csucasestatus"] as EntityReference;
Entity RegardingCase = service.Retrieve(RegardingCaseRef.LogicalName, RegardingCaseRef.Id, new ColumnSet("cos_csucasestatus"));
// inherited from the QueryBase,
trace.Trace("incident");
QueryExpression qeCaseStatus = new QueryExpression("incident");
qeCaseStatus.ColumnSet = new ColumnSet(true);
qeCaseStatus.Criteria.AddCondition(new ConditionExpression("cos_csucasestatus", ConditionOperator.Equal, RegardingCaseRef.Id));
EntityCollection allRelatedCase = service.RetrieveMultiple(qeCaseStatus);
trace.Trace("check boool");
if (CheckcaseStatus(allRelatedCase))
{
trace.Trace("Case title: " + RegardingCase["title"]);


RegardingCase["customersatisfactioncode"] = new OptionSetValue(5);

service.Update(RegardingCase);


}

}
catch
{
throw;
}
}

}
public bool CheckcaseStatus (EntityCollection CaseStatus)
{

if (CaseStatus.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csucasestatus")?.Value == 769190006))
{
//Console.WriteLine("All task completed");
return true;
}
else
{
return false;
}

  • Community Member Profile Picture
    on at
    RE: update Satisfaction

    hi thanks

  • Ray Profile Picture
    1,485 on at
    RE: update Satisfaction

    First of all, you used "cos_csucasestatus" as an EntityReference at the beginning and then as an OptionSetValue, this would throw an exception without doubt. Not sure if this is the root cause of your issue.

    Second, you should always create a new entity instance if you want to update an entity record. Your code should be like this:

    var caseToUpdate = new Entity(RegardingCase.LogicalName, RegardingCase.Id);

    caseToUpdate ["customersatisfactioncode"] = new OptionSetValue(5);

    service.Update(caseToUpdate );

    If you update the entity object base on you retrieved, you may update some extra fields that you do not want, and these fields may trigger additional logic (plugins/workflow/cloud flow). In your code, your update operation will update the "cos_csucasestatus" and "customersatisfactioncode" fields, so any plugin registered on these two fields update will get triggered.

  • Community Member Profile Picture
    on at
    RE: update Satisfaction

     try

                   {

                       trace.Trace("insidetry");

                       Entity incident = (Entity)context.InputParameters["Target"];

                       Entity entity = service.Retrieve("incident", incident.Id, new ColumnSet(true));

                       //chi nhan nhung cot bi thay doi

                       trace.Trace("case");

                       EntityReference RegardingCaseRef = entity["cos_csucasestatus"] as EntityReference;

                       Entity RegardingCase = service.Retrieve(RegardingCaseRef.LogicalName, RegardingCaseRef.Id, new ColumnSet("cos_csucasestatus"));

                       // inherited from the QueryBase,

                       trace.Trace("incident");

                       QueryExpression qeCaseStatus = new QueryExpression("incident");

                       qeCaseStatus.ColumnSet = new ColumnSet(true);

                       qeCaseStatus.Criteria.AddCondition(new ConditionExpression("cos_csucasestatus", ConditionOperator.Equal, RegardingCaseRef.Id));

                       EntityCollection allRelatedCase = service.RetrieveMultiple(qeCaseStatus);

                       trace.Trace("check boool");

                       if (CheckcaseStatus(allRelatedCase))

                       {

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

                           RegardingCase["customersatisfactioncode"] = new OptionSetValue(5);

                           service.Update(RegardingCase);

                       }

                   }

                   catch

                   {

                       throw;

                   }

               }

           }

           public bool CheckcaseStatus (EntityCollection CaseStatus)

           {

               if (CaseStatus.Entities.All(x => x.GetAttributeValue<OptionSetValue>("cos_csucasestatus")?.Value == 769190006))

               {

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

                   return true;

               }

               else

               {

                   return false;

               }

  • Community Member Profile Picture
    on at
    RE: update Satisfaction

    if the user choose casestatus parent is complete is gonna update the satisfaction to sastisfied

    do you have any suggest

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: update Satisfaction

    Your code doesn't look complete. Can you please change it to a compilable state?

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,303 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,025 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans