function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
OlegBOlegB 

Updating "Document" objects

I'm trying to write a routine that would update a file stored in the Document object with a new version of the same file that is located on a specified URL. It *almost* works - I can parse the URL, retrieve the new file and set the body() field on the Document object to the new file's contents, but when I call the update(), the file on the Document object does not get modified. At first I thought that I was setting the body of the file wrong, so tried to update my document object with different file altogether, and that worked... It seems like the update() doesn't like the fact that I update a document object with a file named the same as the one that it's currently point to.

Here's what I'm doing:

Setup:

1. Create a Document object with a file f1.txt and a text "word1" in it and set the Description field to "copyfrom:http:\\localhost\f1.txt"
2. Change the file in the f1.txt on my drive to contain two words "word1, word2"

Tests:

a) Run my code that parses the description, and attempts to update the file on the document object with the new f1.txt file. Result - failure.
The update goes fine (SaveResult = success), the document object's timestamp changes, but when I click a link to a file - I get the old f1.txt with "word1" in it.

b) I rename the file on disk from f1.txt to f2.txt, and update the description on the document object to point to "copyfrom:http:\\localhost\f2.txt" and run my code. Result - success. The link is now opening f2.txt with the text "word1, word2".

Q: Are there any options on the document object I should set before attempting this kind of update ?

Thank you,
Oleg.
DevAngelDevAngel

Sounds like a browser cacheing issue.

Can you just query the document back after updating it, storing it in a temp directory and open it from there?

OlegBOlegB

Yep, you are right. It was the browser caching problem. I cleared cache and now get the correct file.

Thank you!