Some destinations have a max character count for notes. The script below will split notes that exceed that length into multiple notes. The subject of the note will be {original subject} (Part X of Y) and the description will be the first X number of characters for the first note, and the next X number of characters for the second note, etc. The original notes will be marked with a status of Deleted so UM will not try to insert them.
- --Split giant notes into smaller notes.
- DECLARE @targetLEN BIGINT = 250;
- UPDATE __M_Common_Notes SET Final_Status = 'Deleted', Comment = 'Split to multiple notes' WHERE 1=1 AND LEN( Final_Description) > @targetLEN; WITH splitUp AS ( SELECT Id, Final_Parent_Type, Final_Parent_Id, Final_Date, Final_Subject, LEFT( Final_Description, @targetLEN ) notePart, RIGHT( Final_Description, LEN( Final_Description ) - @targetLEN ) remainingNote, 1 partNumber FROM __M_Common_Notes WHERE 1=1 AND LEN( Final_Description ) > @targetLEN
- UNION ALL
- SELECT Id, Final_Parent_Type, Final_Parent_Id, Final_Date, Final_Subject, LEFT (remainingNote, @targetLEN) notePart, IIF(LEN (remainingNote)<=@targetLEN, '', RIGHT (remainingNote, LEN(remainingNote) - @targetLEN)) remainingNote,
- s.partNumber + 1 partNumber
- FROM
- splitUp s
- WHERE 1=1
- AND LEN(remainingNote) >0 ) INSERT INTO __M_Common_Notes ( Id,
- Final_Parent_Type,
- Final_Parent_Id,
- Final_Date,
- Final_Subject,
- Final_Description,
- Final_DisplayOrder ) SELECT CONCAT(Id, ' --- PART ', partNumber) Id, Final_Parent_Type, Final_Parent_Id, Final_Date, CONCAT( Final_Subject, ' (', partNumber, ' of ', COUNT(*) OVER (PARTITION BY Id), ')') Final_Subject, notePart, partNumber FROM splitUp
- GO