Export Customer Notes to an RTF text file

Locked
COBS Tech Support
Site Admin
Posts: 115
Joined: Sat May 15, 2021 9:57 am

Export Customer Notes to an RTF text file

Post by COBS Tech Support »

This script parses the customer table and exports all notes to a text file containing rich text format (RTF) text.

Code: Select all

Declare cHeader Type Character
Declare cNote   Type Character
Declare cFile   Type Character
Declare nCount  Type Number
nCount := 0

cFile := PathCompany() + "NOTESDATA.TXT"

OpenTable("CUSTREC")
CUSTREC->(GotoTop())

If .NOT. CreateFile(cFile)
   Echo("Sorry, file " + cFile + " could not be created. It may open in another application. " + IOError())
   Return
Endif

:Loop
   cNote := ReadRTFNote(2, CUSTREC->Cuscode,, TRUE)

   If .Not. Empty(cNote)
      cHeader := CUSTREC->CUSCODE + "|"
      WriteFile(cFile, IF(nCount > 0, CHR(13) + CHR(10), "") + cHeader + cNote)
      nCount := nCount + 1
   Endif
   
   If CUSTREC->(Skip())
      Goto Loop
   Endif

If .Not. CloseFile(cFile)
   Echo("Error attempting to close export notes data.")
   Return
Endif

If nCount = 0
   Echo("No notes found.")
Else
   Echo("Export completed.")
Endif
Locked