Copy Copying File Attachment from one object no longer works

I have code that was working fine up until yesterday. The custom code copies a file attachment from one object to another (field_422) while also updating one other field, field_426 which is a status field. The status updates but the attachment doesn’t copy but it does delete the file that was in the field.

The payload looks good

However, the preview shows field_422 as blank

And the Response show field_422 as blank

Has anyone else experienced this issue? The only thing that has changed is that our app was moved to a different server the other day. It didn’t solve our response time issue but has caused heartburn with rules not working and now this.

Any help would be appreciated.

Still looking for some help. Has anyone else copied a file attachment from one table to another? The Knack documentation doesn’t address this function. File/Image Uploads

Here is a snippet of my code. I am attempting to move the file in field_746 to field_422 in another object. Does the payload (putData) look correct?

           var data_view = Knack.models['view_1425'].data.toJSON();
            var DO_ref_num = data_view[0].field_746_raw[0].identifier;
            var DO_id = data_view[0].field_746_raw[0].id;      

            var DOfileID = data_view[0].field_745_raw.id;

            var putData = {
                field_426: DOStatus_id,
                field_422: {
                    id: data_view[0].field_745_raw.id,
                    type: data_view[0].field_745_raw.type,
                    filename: data_view[0].field_745_raw.filename,
                    public_url: data_view[0].field_745_raw.url,        
                    thumb_url: "",
                    size: data_view[0].field_745_raw.size,
                    s3: true
                  }
            };
            console.log("putData "+ JSON.stringify(putData));
            var UrlDO = "https://api.knack.com/v1/pages/scene_496/views/view_1145/records/" + DO_id;
          
            var app_id = Knack.app.id;
            var user = Knack.getUserToken();

            var headers = { "X-Knack-Application-ID": app_id, "Authorization": user, "Content-Type":'application/json'};

            $.ajax({
                url: UrlDO,
                type: 'PUT',
                headers: headers,
                async: false,
                data: JSON.stringify(putData),
                success: function() {
                    console.log("file copied from Resubmit to DO record");
                }
         });

Thanks in advance

So, I was finally able to fix the issue. After reading the Knack documentation over and over (it could be clearer), I realized that the document that I am copying is already in Knack and all I needed to do to move it from one object to another was to save the file id in the target object. So the fix was in the payload. field_422 only needs to be updated with the file id.

var putData = {
field_426: DOStatus_id,
field_422: data_view[0].field_745_raw.id
};

1 Like

Thanks for sharing the journey on this @JuliaGlowa31189 - it’ll help someone in future for sure!