Hi,
Here using below code you can get the Parent cases where created date in 1 year older, and using for loop for each parent case you can get the related child case's where origin is "email", and if it gets any record then it will update parent case topic,
Note : i have not tested it, you can create a console application and try to debug it if you get any issue.
************************************************************************
using (service = new OrganizationServiceProxy(new Uri(_organizationURI), null, _credential, null))
{
// get all the case where createon date is 1 year old
QueryExpression getcases = new QueryExpression("incident");
getcases.NoLock = true;
getcases.ColumnSet = new ColumnSet("incidentid","origin", "title", "ownerid", "createdon", "createdby", "parentcaseid", "description");
getcases.AddOrder("createdon", OrderType.Descending);
FilterExpression Filter1 = new FilterExpression(LogicalOperator.And);
Filter1.AddCondition("createdon", ConditionOperator.LessEqual, oneyearolddate);
getcases.Criteria = Filter1;
var retrievecases = service.RetrieveMultiple(getcases);
foreach (var case in retrievecases.Entities)
{
var parentIncidentId = case.Id;
string oneyearolddate = Convert.ToString(DateTime.AddYears(-1));
QueryExpression queryDemande = new QueryExpression("incident");
queryDemande.NoLock = true;
queryDemande.ColumnSet = new ColumnSet("incidentid","origin", "title", "ownerid", "createdon", "createdby", "parentcaseid", "description");
queryDemande.AddOrder("createdon", OrderType.Descending);
FilterExpression Filter1 = new FilterExpression(LogicalOperator.And);
Filter1.AddCondition("parentcaseid", ConditionOperator.Equal, parentIncidentId);
Filter1.AddCondition("createdon", ConditionOperator.LessEqual, oneyearolddate);
queryDemande.Criteria = Filter1;
var linkDemandeAssocie = new LinkEntity("incident", "incident", "parentcaseid","incidentid", JoinOperator.LeftOuter);
linkDemandeAssocie.EntityAlias = "DemandeFille";
linkDemandeAssocie.Columns = new ColumnSet("incidentid","origin", "title", "ownerid", "createdon", "createdby", "parentcaseid", "description");
queryDemande.LinkEntities[0].LinkCriteria.Filters.Add(
new FilterExpression()
{
FilterOperator = LogicalOperator.And,
Conditions =
{
new ConditionExpression("origin", ConditionOperator.Equal, "Email")
}
}
);
queryDemande.LinkEntities.Add(linkDemandeAssocie);
var results = service.RetrieveMultiple(queryDemande);
if(results.Entities.Count>1)
if(((AliasedValue)record["DemandeFille.origin"]).Value.ToString()=="Email")
{
record.attribute["title"] = "Update parent case title";
service.Update(record);
}
}
}
}
************************************************************************
If you find it helpful, Please mark as verified.
Best Regards,
Shahbaaz