Hello Experts,
i have a problem, i try to retrieve Child Records to Update some Attributes but i dont know how to do that.
I read so many Questions and Anwers, blogs and so on but i allways get an Error...
Can anyone help me?
Guid seminarID = Guid.Empty; EntityReference seminarortId = null; EntityReference aref = seminarRef.Get<EntityReference>(executionContext); // Abrufschein ermittlen Entity seminar = service.Retrieve(aref.LogicalName, aref.Id, new ColumnSet("mrd_seminarort")); seminarID = seminar.GetAttributeValue<Guid>("mrd_seminarid"); seminarortId = seminar.GetAttributeValue<EntityReference>("mrd_seminarort"); //Teilnehmer ermitteln Entity teilnehmer = new Entity(); QueryExpression query = new QueryExpression("mrd_teilnehmer"); query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition("mrd_ak_seminarid", ConditionOperator.Equal, seminarID); // query ausführen EntityCollection retrieveedxpan = service.RetrieveMultiple(query); tracingService.Trace(Convert.ToString(retrieveedxpan.Entities.Count)); if (retrieveedxpan.Entities.Count == 0) { // Template nicht gefunden tracingService.Trace("Es wurden keine Teilnehmer gefunden!"); } else { foreach (var entity in retrieveedxpan.Entities) { tracingService.Trace(Convert.ToString(seminarortId)); teilnehmer["mrd_seminarort"] = seminarortId; _serviceProxy.Update(teilnehmer); } }
*This post is locked for comments
Thank you Pawel :)
It works perfectly :)
Have a nice day!
Well currently you are not updating anything as you did not provide ID for the entity you are trying to update. Check this code with my comments:
//Entity teilnehmer = new Entity(); DON'T do this here, you don't have to create it here as you don't use it here QueryExpression query = new QueryExpression("mrd_teilnehmer"); query.ColumnSet = new ColumnSet(true); query.Criteria.AddCondition("mrd_ak_seminarid", ConditionOperator.Equal, seminarID); // query ausführen EntityCollection retrieveedxpan = service.RetrieveMultiple(query); tracingService.Trace(Convert.ToString(retrieveedxpan.Entities.Count)); if (retrieveedxpan.Entities.Count == 0) { // Template nicht gefunden tracingService.Trace("Es wurden keine Teilnehmer gefunden!"); } else { foreach (var entity in retrieveedxpan.Entities) { //now it makes sense to create teilnehmer Entity teilnehmer = new Entity("mrd_teilnehmer"); //but you have to provide name of the entity! teilnehmer.Id = entity.Id; //And for sure you need to provide ID, if you want to update! tracingService.Trace(Convert.ToString(seminarortId)); teilnehmer["mrd_seminarort"] = seminarortId; _serviceProxy.Update(teilnehmer); } }
Hi,
Can you share some details about your entity and related entity and on which event you are registering your plugin.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156