Forum Discussion

Former_Member's avatar
Former_Member
Accelerator III
8 years ago

How to copy a file item when updating

I created item type "myitem" with viewable_file and native_file like Itemtype "CAD". Then, when saving "myitem", I created a method to copy viewable_file to native_file, but it does not work. Could you tell me how to do it? I would like to do the following things. 1, State before saving - viewable_file: A. pdf   -   native_file: (none) 2, Change viewable_file to B.pdf and save. 3, State after saving - viewable_file: B.pdf   -   native_file: B. pdf I created the following method with server event (On BeforeUpdate), but an error occurred and it did not work. ************************************************* var view = this.getPropertyItem ("viewable_file"); var new = inn.newItem (view.getType (), "copyAsNew"); new.setID (view.getID ()); var res = new.apply (); this.setPropertyItem ("native_file", res); ************************************************* error: Sufficient privilege is not set for 'get' operation. Server error (On AfterUpdate) also failed with an error. error: An attemp to copy file (ID = xxxx) after add in the same transaction How do I get the results I expected?

2 Replies

  • Hi Sam, If you are just trying to get the viewable_file to always be the same as the native_file, you could make viewable_file a Foreign property and point it to the ID of the native_file property. This would ensure that the properties both always point to the same file without needing to use a server event. Would this work for your use case or are you should these two properties be the same only under certain situations? Chris
    Christopher Gillis Aras Labs Software Engineer
  • Hi Chris. The viewable_file and the native_file should not be the same item. After copying, convert the viewable_file to another format in the method and replace the original viewable_file. At this time, the native_file and the viewable_file will be different.