Synthesize Missing Matters for Documents

Synthesize Missing Matters for Documents

Some systems only allow documents to be linked to matters.  These scripts will allow you to restore data into these systems. 

When Matters No Longer Exist

The following script with synthesize matters for document related to matters that no longer exist.

  1. --There are documents that are attached to matters that no longer exist
  2. --Create dummy matters out of the missing links.

  3. INSERT INTO __M_Matters (
  4. Id,
  5. Final_ReferenceCode,
  6. Final_Subject,
  7. Final_Description
  8. )
  9. SELECT DISTINCT
  10. Final_Parent_Id,
  11. Final_Parent_Id,
  12. CONCAT('Orphaned Matter ', Final_Parent_Id),
  13. CONCAT('Orphaned Matter ', Final_Parent_Id)
  14. FROM
  15. __M_Documents_Digital_Files
  16. WHERE 1=1
  17. AND Final_Parent_Type = '__M_Matters'
  18. AND Final_Parent_Id NOT IN (SELECT Id FROM __M_Matters)


When Documents are Related to Contacts

If there are documents that are only related to contacts, this script can be used to create a 'General Matter' for each client with documents and restore the documents into those matters.

  1. --There are documents that are only related to matters.
  2. --Create a 'General Matter' for each contact that has documents
  3. --And then move the documents into this matter.

  4. --Variables we can change DECLARE @PREFIX NVARCHAR(MAX) = 'CONTACT --- ' DECLARE @Status NVARCHAR(MAX) = 'Archived' DECLARE @ReferenceCode NVARCHAR(MAX) = 'General Matter' DECLARE @Subject NVARCHAR(MAX) = 'General Matter' DECLARE @Description NVARCHAR(MAX) = 'General Matter' --Create the Matters INSERT INTO __M_Matters (
  5. Id,
  6. Final_Status,
  7. Final_ClientContact_Id,
  8. Final_ReferenceCode,
  9. Final_Subject,
  10. Final_Description
  11. ) SELECT DISTINCT Concat(@PREFIX, Final_Parent_Id),
  12. @Status,
  13. Final_Parent_Id,
  14. @ReferenceCode,
  15. @Subject,
  16. @Description FROM __M_DocumentFiles WHERE 1=1 AND Final_Parent_Type = '__M_Contacts' --Move the documents to the matters we just created UPDATE __M_DocumentFiles SET Final_Parent_Type = '__M_Matters', Final_Parent_Id = CONCAT(@Prefix, Final_Parent_Id) WHERE 1=1 AND Final_Parent_Type = '__M_Contacts'

  17. GO



    • Related Articles

    • Synthesize Missing Practice Areas

      The following SQL script will create practice areas where they do not exist in the Matters table. --Synthesize missing practice areas from Matters INSERT INTO __M_Matters_PracticeAreas( Id, Final_Subject ) SELECT DISTINCT Final_PracticeArea_Id, ...
    • Synthesize: Missing Document Categories for Documents

      The following script will synthesize document categories for invalid Final_DocumentCategory_Id values on documents. -- Some documents are linked to categories that no longer exist. -- Create dummy document categories based on these values. INSERT ...
    • Synthesize Missing Client Contacts for Matters

      This script below will create dummy contacts where the Matter is assigned to a contact that no longer exists. --Some of the Matters are linked to contacts that no longer exist. --This will create dummy contacts from the missing links. INSERT INTO ...
    • Prioritize documents for Active (Open) Matters

      --Prioritize documents for Active (Open) Matters UPDATE __M_Documents_Digital_Files SET Batch_Group = -100 FROM __M_Documents_Digital_Files V1, __M_Matters V2 WHERE 1=1 AND V1.Final_Parent_Id = V2.Id AND V1.Final_Parent_Type = '__M_Matters' AND ...
    • Prioritizing documents based on different criteria

      The following scripts provide examples that can be modified to apply different priorities to documents. Prioritize Large/Small Documents If you are restoring into a system that has different action limits at different times, this can help you ...