Copy Calendar Entry Dates into Custom Field Values

Copy Calendar Entry Dates into Custom Field Values

Some systems let you create custom fields that reference a Calendar Entry.
When moving custom fields into a system that does not support this, an easy workaround would be to turn these custom fields into DateTime custom fields by copying in the start date of the calendar entry.

The script below makes that happen.

  1. --The system we are going into does not support Calendar Entry Custom Fields.
  2. --As a workaround, we are going to copy the date from the calendar entry into the custom field value.

  3. --Copy the date into the custom field values.
  4. UPDATE
  5. __M_CustomField_Values
  6. SET
  7. Final_Value = V3.Final_Date_From
  8. FROM
  9. __M_CustomField_Values V1,
  10. __M_CustomField_Definitions V2,
  11. __M_CalendarEntries V3
  12. WHERE 1=1
  13. AND V1.Original_CustomFieldDefinition_Id = V2.Id
  14. AND V2.Original_Kind = '__M_CalendarEntries'
  15. AND V1.Original_Value = V3.Id

  16. --Update the definitions to be DateTimes instead of Calendar Entries
  17. UPDATE
  18. __M_CustomField_Definitions
  19. SET
  20. Final_Kind = 'DateTime'
  21. WHERE 1=1
  22. AND Final_Kind = '__M_CalendarEntries'