web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

When a user changes the Sales Status to Bought for a Vehicle, close all related tasks of that Vehicle as Completed.

(0) ShareShare
ReportReport
Posted on by

how do i fix this. Thanks everyone

{
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");
try
{
//obtain target entity from the inputparameter
Entity target = (Entity)context.InputParameters["Target"];
//retrive record
Entity entity = service.Retrieve("task", target.Id, new ColumnSet(true));

EntityReference regardingCaseRef = entity["regardingobjectid"] as EntityReference;
//retrive regarding from the back end
trace.Trace("2");
Entity regardingCase = service.Retrieve(regardingCaseRef.LogicalName, regardingCaseRef.Id, new ColumnSet(true));
//retrieve entityrecord from the ms crm server that match the
trace.Trace("4");
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["statuscode"] = new OptionSetValue(912450000);
regardingCase["cre7a_bigfour"] = new OptionSetValue(1);

regardingCase["description"] = "All task update csutaskstatus";
trace.Trace("status check 2");

service.Update(regardingCase);
//update the case status == task status after check if
}

}
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 == 769190000))
{
return true;

}
else
{
return false;
}

}
}

I have the same question (0)
  • Community Member Profile Picture
    on at

       try

               {

                   trace.Trace("inside try");

                   //obtain the target entity from the inputparameter

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

                   //rettrive

                   trace.Trace("retrieve task");

                   Entity entity = service.Retrieve("account", account.Id, new ColumnSet("cre7a_salesstatus"));

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

                   //retrive regarding from the back end

                   trace.Trace("2");

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

                   //retrieve entityrecord from the ms crm server that match the

                   trace.Trace("4");

                   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["statuscode"] = new OptionSetValue(912450000);

                       regardingCase["cos_csucasestatus"] = new OptionSetValue(769190006);

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

                       regardingCase["description"] = "All task update csutaskstatus";

                       trace.Trace("status check 2");

                       service.Update(regardingCase);

                       //update the case status == task status after check if

                   }

               }

               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;

               }

    what do i need to change

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 73 Super User 2026 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#3
11manish Profile Picture

11manish 50

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans