Custom Fields: Creating Custom Fields via Queries

Custom Fields: Creating Custom Fields via Queries

Sometimes you may need to create a new custom field to handle an unmapped column in a database.

The queries below will help you do that.

  1. -- This is the ID we are giving our custom field definition.
  2. DECLARE @FieldId NVARCHAR(MAX) = 'ConNo --- CUSTOM'

  3. --This is a custom field for Contacts
  4. DECLARE @ParentType NVARCHAR(MAX) = '__M_Contacts'

  5. --This first part will create our custom field definition
  6. INSERT INTO __M_CustomField_Definitions (
  7. Id,
  8. Final_Kind,
  9. Final_Parent_Type,
  10. Final_Subject,
  11. Final_Visibility
  12. ) VALUES (
  13. --These are the setting for our custom field definition
  14. 'TextLine', --It is a text line
  15. @FieldId,
  16. @ParentType,
  17. 'Contact Number', --It is named 'Contact Number'
  18. 'Default' --It is visible
  19. )

  20. --This query creates the values.
  21. --In this case, we're creating a custom field definition for a contact.
  22. INSERT INTO __M_CustomField_Values (
  23. Id,
  24. Final_Parent_Id,
  25. Final_Parent_Type,
  26. Final_CustomFieldDefinition_Id,
  27. Final_Value
  28. )
  29. --This part of the query will change based on the table you are pulling values from.
  30. SELECT
  31. --SysId needs to be replaced with the column that
  32. --will match the Id in the __M_Contacts table
  33. CONCAT(SysId, ' --- ', @FieldId),
  34. SysId,
  35. @ParentType,
  36. @FieldId,
  37. con_no --This is the column that contains our custom value.
  38. FROM
  39. --This is the database and table our custom values are coming from.
  40. [LEGACY_TimeMatters_TestDb2].lntmuid.contact

  41. GO

    • Related Articles

    • Flatten Custom Object fields into Contact/Matter Fields

      WARNING: Many systems that support custom objects allow multiple rows in custom objects. Many systems that allow custom fields only allow one single value for each field. When you use this script, if a matter has two values set for the same custom ...
    • Convert User-Select/Contact-Select Custom Fields => Participants

      Some systems do not support User-Select or Contact Select custom fields. The following query will transform User-Select fields into Matter Participants. This script can easily be adapted for Contact-Select fields. -- Transform Custom Fields on ...
    • 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 ...
    • 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 ...