If you connect your exchange mailbox with crm, you might already have appointments in your mailbox. Also, there might be some appointments in CRM.
If you have an appointment in exchange and CRM at the same time, CRM will show you an alert, asking you if you want to import this.
In my case, I always want to import the appointments from Outlook to CRM and I want this automated.
After some searching, I found a solution, based on the blog of a crm developer.
If there is an alert in CRM, where the user has to decide, if the item should be synced, there is an entry in the CRM-database called userdecision in the table exchangesyncidmapping. This attribute cannot be retrieved via the API of CRM, but it can be modified via a plugin.
Therefore, create a plugin that listens on the “Create”-Message of the entity exchangesyncidmapping
And on the “Create”-Message of the Tracelog.
Why on both entities?
The plugin in the exchangesyncidmapping will set the userdecision. This means, that the predefined flag is set on the first synchronization. On the next synchronization, the decision will be interpreted and the item will be synchronized.
If you want to set the status not only for appointments, but also for contacts and tasks, you have to select based on the lastsyncerrorcode:
- 101: appointments
- 102: contacts
- 103: tasks
The Plugin on the tracelog is needed, that the alert will be deleted, after the item is synced. Because this alert will be automatically created, we have to set the flag canbedeleted, that it will be deleted, after the sync.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
var entity = (Entity)Context.InputParameters["Target"]; if (entity.LogicalName == "exchangesyncidmapping") { // There was a appointment conflict. That means, that there is an appointment at the same time like this appointment // The user has to approve, that the appointment should be synced anyway to crm // userdecision: NotApplicable = –1, NotDecided = 0, Confirm = 1, Deny = 2 if (entity.Attributes.ContainsKey("userdecision") && entity.Attributes.ContainsKey("lastsyncerrorcode")) { var userdecision = entity.GetAttributeValue<int>("userdecision"); var lastsyncerrorcode = entity.GetAttributeValue<int>("lastsyncerrorcode"); // 101 => sync conflict for appointments // 102 => sync conflict for contacts if (userdecision == 0 && lastsyncerrorcode == 101) { entity.Attributes["userdecision"] = 1; } if (userdecision == 0 && lastsyncerrorcode == 102) { entity.Attributes["userdecision"] = 2; } } } if (entity.LogicalName == "tracelog") { if (entity.Attributes.ContainsKey("tracecode")) { var tracecode = entity.GetAttributeValue<int>("tracecode"); if (tracecode == 101 || tracecode == 102) { entity.Attributes["canbedeleted"] = true; } } } |