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

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

}
}

  • Community Member Profile Picture
    on at
    RE: When a user changes the Sales Status to Bought for a Vehicle, close all related tasks of that Vehicle as Completed.

       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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February 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... 292,978 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,821 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans