2

I want to load an existing file and append some data, save it back. Tried following in SuiteScript 2.0. But following code still gives me old file content ( only first line when it was created !). Whats wrong?


var fileObj = file.load({
                          id:'SuiteScripts/MergeVendorResults/'+'MergeResult_'+recordId+'.txt'
                    });

                    var oldFileContents = fileObj.getContents();
                    log.debug("Existing file contents","Old File Contents -> "+oldFileContents);
                    fileObj.contents = oldFileContents + "\n"+ fileContents;
                    var id = fileObj.save();
                    fileObj = file.load({
                            id: id
                    });
                    log.debug("Existing file replaced with contents","File Contents -> "+fileObj.getContents());
FreeMarker12
  • 115
  • 1
  • 10

1 Answers1

3

You need to create a whole new file object with the concatenated contents and the original file's name and folderId. Then when you save it'll overwrite the original file.

bknights
  • 14,408
  • 2
  • 18
  • 31