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

how can i change it to early bound

(0) ShareShare
ReportReport
Posted on by

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 regar dingobjectid 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
    RE: how can i change it to early bound

    Entity taskRecord = new Entity("task");

                       taskRecord.Attributes.Add("subject", "Minhboss");

                       taskRecord.Attributes.Add("description", "Employee1");

                       //Initializes a new instance of the EntityReference class.

                       taskRecord.Attributes.Add("regardingobjectid", entity.ToEntityReference());

                       Guid taskGuild = service.Create(taskRecord);

    how ab this can i write in early bound

  • Suggested answer
    Abdul Wahab Profile Picture
    12,085 Moderator on at
    RE: how can i change it to early bound

    Hi minh nhat,

    We can not say it rewrites the code. We could say it is the enhancement of code. Using early bound you can get errors of Entity Data Model (EDM) used by Dataverse in the compile-time.

    If I answer your question then mark it as verified.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

  • Community Member Profile Picture
    on at
    RE: how can i change it to early bound

    Hi i need to rewrite this code to early bound

  • Suggested answer
    Abdul Wahab Profile Picture
    12,085 Moderator on at
    RE: how can i change it to early bound

    Hi minh nhat,

    You can find details in the link.

    Let me know if I can provide you with more details.

    Thanks
    Regards,

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit
    Linkedin: www.linkedin.com/.../

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 Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 91

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans