Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

i have this code when task rejected and the case the csu case status will be reject

(0) ShareShare
ReportReport
Posted on by

i have this code when task rejected and the case the csu case status will be reject

try
{
trace.Trace("inside try");
//obtain the target entity from the inputparameter
Entity target = (Entity)context.InputParameters["Target"];
//rettrive
trace.Trace("retrieve task");
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);
trace.Trace("check bool");
if (AllTaskReject(relatedTasks))
{
//resovle the case
//769190006 //create an incident
trace.Trace("create incident");
Entity IncidentResolution = new Entity("incidentresolution");
IncidentResolution.Attributes["subject"] = "Subject Closed";
trace.Trace("inheritance");
//Inheritance OBJECT
IncidentResolution.Attributes["incidentid"]= new EntityReference("incident",entity.Id);
IncidentResolution.Attributes["cos_csucasestatus"] = new OptionSetValue(806570002);
service.Update(IncidentResolution);
}

}
catch (FaultException ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}

}

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

  • Suggested answer
    Bipin D365 Profile Picture
    28,981 Moderator on at
    RE: i have this code when task rejected and the case the csu case status will be reject

    Hi,

    Change service.Update(incidentResolution)

    To

    service.Create(incidentResolution);

    Also, best practise is to not pass true in ColumnSet which will impact the performance.

    You shouldn't use below

    new ColumnSet (true);

    Instead pass the fields logicalname you want to retrieve and use in your program.

    I hope this helps!

  • Community Member Profile Picture
    on at
    RE: i have this code when task rejected and the case the csu case status will be reject

    hi so i have csu case status

    reject value will be 806570002

    so i update csucasestatus by this

    Entity incident = new Entity("incident");

                       incident.Id = regardingCaseRef.Id;

                       incident.Attributes["cos_csucasestatus"] = new OptionSetValue(806570002);

                       service.Update(incident);

    is this correct

  • Verified answer
    Abdul Wahab Profile Picture
    12,085 Moderator on at
    RE: i have this code when task rejected and the case the csu case status will be reject

    Hi minh nhat,

    So what do you want from the community? Can you please elaborate on the problem more?

    If I answer your question then please 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/.../

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
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Sahra Profile Picture

Sahra 43

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans