Moving Documents into Matters that are Nested under Other Entries

Moving Documents into Matters that are Nested under Other Entries

Some systems allow documents to be nested under virtually any other kind of record.  This can be challenging when moving documents into systems that have a limited number of parent types.



  1. --The following script creates a "MISC DOCUMENTS" matter
  2. --And then moves any documents that do not have a valid Parent Type into this matter.

  3. GO

  4. DECLARE @Id NVARCHAR(MAX) = 'MISC DOCUMENTS'
  5. DELETE FROM __M_Matters WHERE Id = @Id
  6. INSERT INTO __M_Matters (Id, Final_Subject)
  7. VALUES (@Id, @Id)

  8. UPDATE
  9. __M_Documents_Digital_Files
  10. SET
  11. Final_Parent_Id = @Id,
  12. Final_Parent_Type = '__M_Matters',
  13. Final_Folder_RelativePath = CASE 
  14. WHEN COALESCE(Final_Created_At, Final_Updated_At) IS NULL THEN CONCAT('\', Final_Parent_Type, Final_Folder_RelativePath)
  15. ELSE CONCAT('\', Final_Parent_Type, '\', FORMAT( COALESCE(Final_Created_At, Final_Updated_At), 'yyyy-MM'), Final_Folder_RelativePath)
  16. END
  17. WHERE 1=1
  18. AND Final_Parent_Type NOT IN (
  19. --Update this to have the list of valid document Parent Types for your destination.
  20. '__M_Contacts',
  21. '__M_Matters'
  22. )