Skip to main content
Question

File Attachment HELP

  • December 13, 2019
  • 0 replies
  • 362 views

Hello all!
I need to know how I can get file attachments from one table to another. I'm currently using the automation tool to get everything else over.

------------------------------
Adrinie Freeman
------------------------------
This topic has been closed for replies.

  • Registered
  • December 13, 2019
This can't be done natively, but can be done with a Code Page or a formula button that will execute this. This is not my code, but Dan Diebolt's. He used to be very active on these boards.

(() => {

  let dbidSource = "YOUR SOURCE DBID";

  let ridSource = "YOUR SOURCE [Record ID#]";

  let fidSource = "YOUR SOURCE FIELD ID";

 

  let dbidTarget = "YOUR TARGET DBID";

  let ridTarget = "YOUR TARGET [Record ID#]";

  let fidTarget = "YOUR TARGET FIELD ID";

 

  let copyFile = (dbidSource, ridSource, fidSource, dbidTarget, ridTarget, fidTarget) => {

    return new Promise(resolve => {

      let urlFileName = `${dbidSource}?a=q&query={3.EX.${ridSource}}&clist=${fidSource}&opts=csv`;

      fetch(urlFileName, {

        method: "GET",

        credentials: "include"

      }).then(response => {

        return response.text();

      }).then(response => {

        let filename = response.split("\n")[1].trim();

        let urlFileSource = `/up/${dbidSource}/a/r${ridSource}/e${fidSource}/v0`;

        fetch(urlFileSource, {

          method: "GET",

          credentials: "include"

        }).then(response => {

          return response.blob();

        }).then(myBlob => {

          let myform = new FormData();

          myform.set("subact", "save");

          myform.set("rid", ridTarget);

          myform.append(`_fid_${fidTarget}`, myBlob, filename);

          let urlFileTarget = `${dbidTarget}?a=FinishEditRecord`;

          fetch(urlFileTarget, {

            method: "POST",

            body: myform,

            credentials: "include"

          }).then(response => {

            resolve();

          });

        });

      });

    });

  };        

 

  copyFile(dbidSource, ridSource, fidSource, dbidTarget, ridTarget, fidTarget).then(() => {

    console.log("all done");

  });

 

})();



------------------------------
Ryan Stanford
------------------------------

KeithJusas
Forum|alt.badge.img+7
  • Registered
  • December 14, 2019
We have an add-on service that can sweep the files for you if you don't want to code the process yourself.  Can also process in bulk based on a report filtered to identify the records to process.
 
demo here: https://juicedtech.quickbase.com/db/bmzi5qjk7

------------------------------
Keith Jusas
------------------------------