Moving Documents into Matters that are Nested under Communications

Moving Documents into Matters that are Nested under Communications



  1. --The following script moves documents that are nested under Communications to be nested under Matters instead.
  2. UPDATE
  3. __M_Documents_Digital_Files
  4. SET 
  5. Final_Folder_RelativePath = '\Emails\',
  6. Final_Parent_Type = Relationships.Final_RelatedTo_Type,
  7. Final_Parent_Id = Relationships.Final_RelatedTo_Id
  8. FROM
  9. __M_Documents_Digital_Files Documents,
  10. __M_Communications Parents,
  11. __M_Communications_Related_Entities Relationships
  12. WHERE 1=1
  13. AND Documents.Final_Parent_Type = '__M_Communications'
  14. AND Documents.Final_Parent_Id = Parents.Id
  15. AND Parents.Id = Relationships.Final_Communication_Id
  16. AND Relationships.Final_RelatedTo_Type = '__M_Matters'