Some systems only allow documents to be linked to matters. These scripts will allow you to restore data into these systems.
The following script with synthesize matters for document related to matters that no longer exist.
- --There are documents that are attached to matters that no longer exist
- --Create dummy matters out of the missing links.
- INSERT INTO __M_Matters (
- Id,
- Final_ReferenceCode,
- Final_Subject,
- Final_Description
- )
- SELECT DISTINCT
- Final_Parent_Id,
- Final_Parent_Id,
- CONCAT('Orphaned Matter ', Final_Parent_Id),
- CONCAT('Orphaned Matter ', Final_Parent_Id)
- FROM
- __M_Documents_Digital_Files
- WHERE 1=1
- AND Final_Parent_Type = '__M_Matters'
- AND Final_Parent_Id NOT IN (SELECT Id FROM __M_Matters)
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.
- --There are documents that are only related to matters.
- --Create a 'General Matter' for each contact that has documents
- --And then move the documents into this matter.
- --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 (
- Id,
- Final_Status,
- Final_ClientContact_Id,
- Final_ReferenceCode,
- Final_Subject,
- Final_Description
- ) SELECT DISTINCT Concat(@PREFIX, Final_Parent_Id),
- @Status,
- Final_Parent_Id,
- @ReferenceCode,
- @Subject,
- @Description FROM __M_Documents_Digital_Files WHERE 1=1 AND Final_Parent_Type = '__M_Contacts' --Move the documents to the matters we just created UPDATE __M_Documents_Digital_Files SET Final_Parent_Type = '__M_Matters', Final_Parent_Id = CONCAT(@Prefix, Final_Parent_Id) WHERE 1=1 AND Final_Parent_Type = '__M_Contacts'
- GO