1

Can anyone say that how to fetch the 'requiredattendees' of appointment when appointment gets deleted. On delete of appointment I need to perform update on those attendees. I am not getting values in that party list either on PRE or POST.

Even PreImage entity is not capturing the information of only that 'requiredattendees' field, rest fields are ok in that PreImage entity.

Can anyone say that what I am doing wrong ?

Thank You very much.

Anish
  • 588
  • 6
  • 21
  • The entity image itself will not have related records, you need to fetch the related records. – dynamicallyCRM Jan 18 '17 at 20:39
  • I have tried this, it not worked. Main issue is that when I debug it, it works fine..when I don't debug, it does not work. :( – Anish Jan 19 '17 at 10:25
  • Looks like data issue to me, are you using the same record in both cases? logically it should matter if you are debugging it or not. – dynamicallyCRM Jan 19 '17 at 16:14
  • No, it is not data issue. you need profiled error tod ebug the plugin and when profiler is on, delete operation will get completed and that record still exist in CRM, you can refresh the grid you will get the record. Now when I debug it fetches the values from same record. – Anish Jan 20 '17 at 05:20

2 Answers2

2

You need to retrieve the list of child records in a PreValidation plugin as cascading deletes/disassociations may occur before PreOperation.

Assuming you transnational integrity you should gather this information in PreValidation and save it (IPluginExecutionContext.SharedVariables is a good place to save the guids.) In a PreOperation or PostOperation plugin you can execute your logic against the list of required attendee guids you stored.

Nicknow
  • 7,154
  • 3
  • 22
  • 38
0

Assuming you have registered the plugin on Delete Preoperation

var appointment = pluginExecutionContext.InputParameters["Target"] as EntityReference;
var response = organizationService.Retrieve("appointment", appointment.Id, new ColumnSet("requiredattendees"));
var requiredAttendees = response.GetAttributeValue<EntityCollection>("requiredattendees");

foreach (var attendee in requiredAttendees.Entities)
{
       //your logic
}
dynamicallyCRM
  • 2,980
  • 11
  • 16
  • I have tried this first time and it did not work, so tried for PreImage and that also not worked. :( I can try the above of above approach. Will update here. – Anish Jan 19 '17 at 10:20
  • I created a plugin just to test this out and worked for me. Did you register your plugin on pre-op? – dynamicallyCRM Jan 19 '17 at 16:13
  • Yes, ofcourse. In your case, you are able to fetch the partylist of field 'requiredattendees' without debugging plugin registered on PreOperation of Appointment(Delete) in sync mode ? – Anish Jan 20 '17 at 05:18