Convert Any Field into a Picklist

Convert Any Field into a Picklist

The following script lets you convert any field into a picklist.


  1. --This script will convert any field (usually text fields) into Picklists
  2. --and generate Picklist Options from the values.
  3. GO


  4. DECLARE @Ids Table(Id NVARCHAR(MAX))
  5. INSERT INTO
  6. @Ids
  7. VALUES
  8. --Enter all the IDs of Custom Field Definitions we want to Convert
  9. (''),
  10. (''),
  11. ('')

  12. --Look at the Options table and the Values table and generate any items that dont already exist
  13. INSERT INTO
  14. __M_CustomField_Definitions_Options
  15. (
  16. Id, Final_Subject
  17. )
  18. SELECT DISTINCT
  19. CONCAT(V2.Id, ' --- ', V1.Final_Value),
  20. V1.Final_Value
  21. FROM
  22. __M_CustomField_Values V1,
  23. __M_CustomField_Definitions V2
  24. WHERE 1=1
  25. AND V2.Id = V1.Final_CustomFieldDefinition_Id
  26. AND V2.Id IN (
  27. SELECT Id from @Ids
  28. )
  29. AND CONCAT(V2.Id, ' --- ', V1.Final_Value) NOT IN (
  30. SELECT
  31. Id
  32. FROM
  33. __M_CustomField_Definitions_Options
  34. )

  35. --If we want to convert a field into a Picklist, Run the below script.
  36. UPDATE
  37. __M_CustomField_Definitions 
  38. SET
  39. Final_Kind = 'PickList'
  40. WHERE 1=1
  41. AND Id in (
  42. SELECT Id from @Ids
  43. )

  44. --Then update the Options table to reference the new items.
  45. UPDATE
  46. __M_CustomField_Values
  47. SET
  48. Final_Value = CONCAT(V2.Id, ' --- ', V1.Final_Value)
  49. FROM
  50. __M_CustomField_Values V1,
  51. __M_CustomField_Definitions V2
  52. WHERE 1=1
  53. AND V2.Id = V1.Final_CustomFieldDefinition_Id
  54. AND Final_Value NOT IN(
  55. SELECT
  56. Id
  57. FROM
  58. __M_CustomField_Definitions_Options
  59. )
  60. AND V2.Id In (
  61. SELECT Id from @Ids
  62. )


  63. GO


    • Related Articles

    • Convert a Custom Field into a Practice Area

      --The system we are coming from does not have practice areas --however, the client has created a picklist custom field that mimics this. --We are going to convert this custom field into a practice area. --First, populate the practice areas table with ...
    • Copy a Custom Field into a Core Field

      Some systems don't have certain core fields and clients often create a custom field that they use instead. The following script will let you copy values from a custom field named 'Opened' into __M_Matters.Final_Date_Opened . You can adjust this ...
    • Create a "Legacy Matter Number" Custom Field

      Some firms rely heavily on Matter Numbers to search for a specific matter. Sometimes when they migrate to a new system it can't replicate the automatic numbering system from their old system so they want to renumber all their matters to a new scheme ...
    • Create an "Employer" Contact from a Custom Field.

      In some systems, contacts do not have an Employer relation and only have a text field that represents the employer. This script will help when moving firms into platforms that allow an actual contact to be specified for the employer. --Create Company ...
    • 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 ...