0

How to copy PDF file from Image field to new record.

Hi there!

Hope someone already had to go through this: I'm copying records from one table to another (and then deleting them). Everything seems to be fine, except for the field image containing a PDF file. It only copies the file name but not the content. I've tried to figure it out using Importfile command, but so far, nothing.

Here's my coding:

 

if Contabilizar = true then
    let recID := count(select 'Asientos por Registrar');
    ID_Record := format(recID, "000") + 1;
    let newid := ID_Record;
    let x := this;
    let repes := count((select 'Asientos Contabilizados')['Fecha Asiento' = x.'Fecha Asiento' and Movimiento = x.Movimiento and
                    number(Importe) = number(x.Importe) and
                ID_Record = x.ID_Record]);
    if repes = 0 then
        let contab := (create 'Asientos Contabilizados');
        contab.(ID_Record := x.ID_Record);
        contab.('Fecha Asiento' := x.'Fecha Asiento');
        contab.(Movimiento := x.Movimiento);
        contab.(Importe := x.Importe);
        contab.('Cuenta de Cargo' := x.'Cuenta de Cargo');
        contab.('Cuenta de Abono' := x.'Cuenta de Abono');
        contab.('Compras / Contratos Cesión' := x.'Compras / Contratos Cesión');
        contab.(Ventas := x.Ventas);
        contab.(Gastos := x.Gastos);
        contab.(Inventario := x.Inventario);
        contab.(Comprobante := x.Comprobante); ---> both fields are image fields of course
        dialog("Contabilizar Asiento", "Asiento contabilizado correctamente!", ["OK"]);
        delete x
    else
        dialog("Contabilizar Asiento", "ERROR! No se ha contabilizado este asiento", ["OK"])
    end
else
    dialog("Contabilizar Asiento", "Marque la casilla para contabilizar asiento", ["OK"])
end

 

Thanks for any help!!

16 replies

null
    • Daniel_Berrow
    • 1 yr ago
    • Reported - view

    Try

    contab.(comprobante := importFile(contab, shareFile(x.Comprobante), contab.text(id) + ".pdf"))
      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      thank you for replying so fast!

      I'm probably missing something as I'm getting an error in the contab.text(id) command. "id" should be pointing to a field?

      • Daniel_Berrow
      • 1 yr ago
      • Reported - view

       I was trying to make the PDF name unique per record, as sometimes this causes an issue in loop. You may be able to get away with it and just use the formula

      contab.(comprobante := importFile(contab, shareFile(x.Comprobante))
      
      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      just tried both ways, but still doesn't copy the file into the new record. =(

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

       Perhaps the problem lies in the way the record is created. The create function returns a Node. And I think importFile wants a NID.
      Try creating your new record like this: 

      let contab := (create 'Asientos Contabilizados').ID;
      
      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      thanks for joining in! I've tried your suggestion (even made a test DB) and it creates a blank record. I'm even exploring the option of using the files(this) function and instead of uploading the PDF into the image field, use the attachment option on the record. But also can't figure out how to code it into the create structure. Now I'm feeling a bit dizzy about this =/

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

       Can you share the test database with us?

      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      sure! I made a pretty simple db just to try to replicate the effect. FYI I've added a PDF on the image field and another as attachment. I was just trying every coding option I can think of.

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

        Marisol Echaide This code is used to copy all the files from one record to another :

      let myrec := this;
      let docu := files(this);
      let newrec := (create 'Tabla B').Id;
      for f in docu do
          var share := shareFile(f);
          var fileName := extractx(text(f), "\/(.*)", "$1");
          alert(---
      Copy in progress : { fileName }...
          ---);
          importFile(newrec, share, fileName);
          unshareFile(f)
      end;
      alert("Finished")

       

      You can also copy a single image field into the image field of another record: 

      let newrec := (create 'Tabla B').Id;
      var share := shareFile(Imagen);
      var fileName := extractx(text(Imagen), "\/(.*)", "$1");
      newrec.(Imagen := importFile(newrec, share, fileName));
      unshareFile(Imagen)
      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

      Jacques TUR  Hi Jacques I test the db, in my case

      The Copy all files button does not copy anything to the other table.

      The Copy image yes copy the image to another table.

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

       Here is my result when I click on the Copy all files button:

      • Rafael Sanchis
      • Rafael_Sanchis
      • 1 yr ago
      • Reported - view

       Is all ok Jacques 👍

    • Marisol_Echaide
    • 1 yr ago
    • Reported - view

    Sorry for the delay , I've been away for a few days.

    There must be something wrong with my app or something. I've imported your DB and both buttons create a blank record.

    Might be something to do with the fact that I'm working with Ninox as native app (computer based)?

      • Ninox developper
      • Jacques_TUR
      • 1 yr ago
      • Reported - view

       Yes, it works with the cloud, but not with the application because shareFile is not implemented. I haven't found a solution yet. 

      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      Thank you anyways! As I'm building the DB in local before going in the cloud I'm probably leaving this for later on. Thanks again for your work and time!

    • Marisol_Echaide
    • 1 yr ago
    • Reported - view

    Following on this thread I just wanted to share my latest attempt in case it opens the possibility for a solution.

    It's clear to me that the sharefile() function is not available on the native app, but that every attached filed always has a URL. In this case, located in my local drive.

    So, I began testing based on my very limited knowledge 😅 and so far I managed to extract the URL from the file in my local drive. I also tested to use that extracted URL to import the file. And it seems to work within the same record. However 😕 I can't manage to replicate that when copying it to a different table. I'm attaching again my tester DB so you can see what I came up with. I don't know if I could be on the right track or just wandering off the road out of desperation.

Content aside

  • 1 yr agoLast active
  • 16Replies
  • 221Views
  • 4 Following