public static string GetEntityUrl(this ConnectionDetail connectiondetail, Entity entity) { if (entity == null) { return(string.Empty); } var entref = entity.ToEntityReference(); switch (entref.LogicalName) { case "activitypointer": if (!entity.Contains("activitytypecode")) { MessageBox.Show("To open records of type activitypointer, attribute 'activitytypecode' must be included in the query.", "Open Record", MessageBoxButtons.OK, MessageBoxIcon.Error); entref.LogicalName = string.Empty; } else { entref.LogicalName = entity["activitytypecode"].ToString(); } break; case "activityparty": if (!entity.Contains("partyid")) { MessageBox.Show("To open records of type activityparty, attribute 'partyid' must be included in the query.", "Open Record", MessageBoxButtons.OK, MessageBoxIcon.Error); entref.LogicalName = string.Empty; } else { var party = (EntityReference)entity["partyid"]; entref.LogicalName = party.LogicalName; entref.Id = party.Id; } break; } return(connectiondetail.GetEntityReferenceUrl(entref)); }