Convert Any Field into a Picklist
The following script lets you convert any field into a picklist.
- --This script will convert any field (usually text fields) into Picklists
- --and generate Picklist Options from the values.
- GO
- DECLARE @Ids Table(Id NVARCHAR(MAX))
- INSERT INTO
- @Ids
- VALUES
- --Enter all the IDs of Custom Field Definitions we want to Convert
- (''),
- (''),
- ('')
- --Look at the Options table and the Values table and generate any items that dont already exist
- INSERT INTO
- __M_CustomField_Definitions_Options
- (
- Id, Final_Subject
- )
- SELECT DISTINCT
- CONCAT(V2.Id, ' --- ', V1.Final_Value),
- V1.Final_Value
- FROM
- __M_CustomField_Values V1,
- __M_CustomField_Definitions V2
-
- WHERE 1=1
- AND V2.Id = V1.Final_CustomFieldDefinition_Id
- AND V2.Id IN (
- SELECT Id from @Ids
- )
- AND CONCAT(V2.Id, ' --- ', V1.Final_Value) NOT IN (
- SELECT
- Id
- FROM
- __M_CustomField_Definitions_Options
- )
- --If we want to convert a field into a Picklist, Run the below script.
- UPDATE
- __M_CustomField_Definitions
- SET
- Final_Kind = 'PickList'
- WHERE 1=1
- AND Id in (
- SELECT Id from @Ids
- )
- --Then update the Options table to reference the new items.
- UPDATE
- __M_CustomField_Values
- SET
- Final_Value = CONCAT(V2.Id, ' --- ', V1.Final_Value)
- FROM
- __M_CustomField_Values V1,
- __M_CustomField_Definitions V2
- WHERE 1=1
- AND V2.Id = V1.Final_CustomFieldDefinition_Id
- AND Final_Value NOT IN(
- SELECT
- Id
- FROM
- __M_CustomField_Definitions_Options
- )
- AND V2.Id In (
- SELECT Id from @Ids
- )
- 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 ...
Custom Field Kinds
The following is a list of the valid Kinds of custom fields. Kind Notes TextLine TextArea HtmlArea Number Represents any kind of number. Integer Represents only whole numbers Money Date Time TimeSpan Represents durations. DateTime EmailAddress ...
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 a "Legacy Client Number" Custom Field
Some firms rely heavily on Client Numbers to search for a specific client. 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 ...