SQL Spreadsheets: Cherry-Picking Custom Fields

SQL Spreadsheets: Cherry-Picking Custom Fields

The following SQL command will generate a Google Sheet that users can use to cherry-pick custom field definitions.

  1. SELECT
  2. '' as 'Keep? (Y)',
  3. V1.Id,
  4. V1.Final_Parent_Type,
  5. V1.Final_Kind,
  6. V1.Final_Subject,
  7. V1.Final_Description, V1.Final_Status,
  8. COALESCE(V2.Count, 0) as 'TimesUsed',

  9. Script = CONCAT(''
  10. --IF cell A### = "Y"
  11. , '=IF(INDIRECT("A"&ROW()) = "Y",'
  12. --THEN: Generate the script using the ID in cell B###.
  13. , '"'
  14. , ' UPDATE'
  15. , ' __M_CustomField_Definitions'
  16. , ' SET'
  17. , ' Final_Status = ''Active'', '
  18. , ' Final_Subject = '
  19. , ' ''" & '
  20. , ' SUBSTITUTE(INDIRECT("E"&ROW()), "''", "''''") '
  21. , ' & "'''
  22. , ' WHERE 1=1'
  23. , ' AND Id = '
  24. , ' ''" & '
  25. , ' INDIRECT("B"&ROW()) '
  26. , ' & "'''
  27. , '"'
  28. --/THEN
  29. , ', '
  30. --ELSE
  31. , '"'
  32. , ' '
  33. , '"'
  34. --/ELSE
  35. , ')'
  36. )
  37. FROM
  38. __M_CustomField_Definitions V1
  39. LEFT JOIN
  40. (
  41. SELECT
  42. Final_CustomFieldDefinition_Id as 'Id',
  43. Count(*) as 'Count'
  44. FROM
  45. __M_CustomField_Values
  46. GROUP BY
  47. Final_CustomFieldDefinition_Id
  48. ) AS V2
  49. ON V1.Id = V2.Id
  50. ORDER BY
  51. Final_Parent_Type, Final_Subject

 
Once you generate the Google Sheet, you should share it with your customer with instructions similar to the following:
Replace references to the "legacy environment" and "new system" to be the actual names of the systems.

---

Hi Customer,

In prep for restoring your data to the [new system], I need you to fill out the Google Sheet included in this email.

The spreadsheet lists all custom field definitions your firm has defined and how many times each one is used.

For each field that you would like to keep, place a in column A.

When choosing each field, you should only select the fields that are important and frequently used.

For example, if you have a field that you feel is important but is seldom used, use your own judgement, but we generally recommend not cluttering your new system with it.


If you have any questions, please feel free to reach out.