FreeMarker12
FreeMarker12

Reputation: 115

Editing exising file in SuiteScript 2.0

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());

Upvotes: 2

Views: 2259

Answers (1)

bknights
bknights

Reputation: 15367

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.

Upvotes: 3

Related Questions