Overwrite existing file object

Hi,

I have an object class called Image Return. In one view I create new objects in Image Return RT (runtime only) and upload images. When I press save, the objects are persisted to server. Later I can open another view where I see the images (when I open the view, I read objects from Image Return to Image Return RT). Here I have enabled the pen tool, so that you can draw on the images. But when I press save and want to persist objects to server, I get this error: Error: Tried to overwrite existing file object.

I want to replace the object in Image Return (the image without the drawing) with the object in Image Return RT (the image with the drawing). How can I do that?

Hi Siri,

Thank you for your question! It is intended behaviour that users are prevented from overwriting existing file objects. Here is a step by step guide to how I have been able to get this process to work:

  1. Add a runtime property to Image Return RT called “Reference”, with type Boolean.
  2. Set up an “On View Load” action for the View which shows the images. First, read the required images to Image Return RT as you were doing before. Then, iterate each image in Image Return, and create a new file object in Image Return RT using the process outlined here to duplicate file objects. Make sure that the “Replace Existing Objects” checkbox is NOT enabled. For each of these file objects created, assign the runtime property “Reference” to true. Now, some items in Image Return RT will be “copies” of the original images, while some are direct references.
  3. Set up the UI in the View so that it only shows the user the images with “Reference” set to true. Users can draw on these images as before.
  4. When saving and persisting, you can persist a filtered selection of objects (those with “Reference” set to true). Then, iterate through the items in Image Return RT where “Reference” NOT EQUALS true, and for each one, delete the item in Image Return with matching ID.

This will persist the edited versions of the images to the server, and then delete the original versions stored on the server afterwards.

Let me know if there’s any questions, or if you need any help with this setup :slight_smile:

Rhys