Split Big Notes

Split Big Notes

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. 

  1. --Split giant notes into smaller notes.
  2. DECLARE @targetLEN BIGINT = 250;

  3. 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

  4. UNION ALL

  5. 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,
  6. s.partNumber + 1 partNumber
  7. FROM
  8. splitUp s
  9. WHERE 1=1
  10. AND LEN(remainingNote) >0 ) INSERT INTO __M_Common_Notes ( Id,
  11. Final_Parent_Type,
  12. Final_Parent_Id,
  13. Final_Date,
  14. Final_Subject,
  15. Final_Description,
  16. 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

  17. GO



    • Related Articles

    • Linearize Notes

      Some systems support note comments(notes-on-notes). On systems like this, you might see notes organized as follows: |-Matter ABC.001 +-Note 1 (2021-01-01) +-Note 2 (2021-01-02) +-Note 2A (2021-01-04) +-Note 2B (2021-01-05) +-Note 2C (2021-01-06) ...
    • Promote Document Version Notes to Document Notes

      --The following script will promote document version notes --into document notes. This is useful when a destination system --supports notes on documents but does not support notes on --specific document versions. -- --If you are using this script, ...
    • Create Notes from Matter Descriptions

      Some platforms do not support matter descriptions. The following will transform a matter description into a matter note. --Transform Matter Descriptions to Matter Notes INSERT INTO __M_Common_Notes (Id, Final_Parent_Id, Final_Parent_Type, ...
    • Notes: Add Creator Information to the Body

      The script below will append the text 'Created By: {firstName lastName}', 'Created on behalf of: {firstName lastName}', and 'Updated by: {firstName lastName}' to the end of the note description in cases where the user's Email address was changed on ...
    • Prioritizing documents based on different criteria

      The following scripts provide examples that can be modified to apply different priorities to documents. Prioritize Documents by "Max Matter Date" All the documents in a matter are prioritized based on the Created/Modified date of the most recently ...