0

button for Duplicate a record and its links to a sub table

Hello Community!

I needs some help to create a button in my table Navire.

Each record of Navire has multiple links to another table Options (1:N)

This allow to create a navire with its own options.

Now I would like to create a button which can duplicate a selected navire with all its own options.

It should sound like for a navire x : duplicate(this) where Option:= navire x

But I'm lost with this kind of script.

So help appreciated!

thanks a lot!

14 replies

null
    • Daniel_Berrow
    • 1 yr ago
    • Reported - view

    Are you trying to duplicate a Navire record but reset the options that are linked with it, to then create its own options?

      • frsalabert.1
      • 1 yr ago
      • Reported - view

       hello Daniel: thanks for your help! i want navire to keep all its option and navire.duplicated getting the same option... like a clone!

    • Fred
    • 1 yr ago
    • Reported - view

    If you had a button in the Navire table, it would look something like:

    let t := this;
    let newRec := duplicate(t);
    for loop1 in t.Options do
     let newOp := duplicate(loop1);
     newOp.Navire := newRec
    end
    

    Lines 1 and 2 are probably what you expect.

    Lines 3 - 6 is the for loop that takes each related record in Options of the current Navire record and duplicates it then links it to the newly duplicated record in line 2.

      • frsalabert.1
      • 1 yr ago
      • Reported - view

      thanks Fred! I will try it!

      • frsalabert.1
      • 1 yr ago
      • Reported - view

       it just works!! you're awesome!!... i need to study my loop function right now!

    • frsalabert.1
    • 1 yr ago
    • Reported - view

    Hello Fred! hope you're still listen! I tried many loop for a new purpose after the duplicate button. Without success... When I have my new vessel with its news options in my vessel table (thanks to your script) , I would also like to link all those newly created options to an existing record in my Offer table. Maybe in the same script as the duplicate button, so in one shot I could duplicate a vessel and link its options to an existing offer or to a new one if it is too complicated script to access a dedicated record in the offer table... thanks again for your help!

      • Fred
      • 1 yr ago
      • Reported - view
       said:
      I could duplicate a vessel and link its options to an existing offer or to a new one if it is too complicated script to access a dedicated record in the offer table

      Sounds like you will need a way to tell the script if you want to use an existing Offer record or create a new one. Probably a new field next to the duplicate button? So then you would create a variable that has the if then statement that would either create a new Offer record or find an existing one. Now you have a record Id that you can use in your new vessel.

      • frsalabert.1
      • 1 yr ago
      • Reported - view

       Nice to ear you again! usually I 've already created my new offer which is like to a client. Then manually I duplicate the vessel and its options (thanks to your script), and still manually I link the vessel to this new offer. Which is a good way to me. But that way new options are not linked to the offer (only the vessel is) and I have a lot of options (right now, I link them one by one to the offer.. a pain in the a**)! I would appreciate to link directly the duplicated vessel AND its options to an existing offer in the same script. So I can rename my duplicate button in "duplicate and link all" and When I click on it the system show me the list of offers, I choose the good one and both new vessel and its new options are linked to the offer (it looks so easy!😅). Does it sound doable?...

      • Fred
      • 1 yr ago
      • Reported - view
       said:
      I would also like to link all those newly created options to an existing record in my Offer table.

       Do the Options need to be linked directly to an Offres? If they are linked to a Navire and a Navire is linked to an Offres then those Options are linked to the Offres. To access the Options you can create a view element and put:

      Navire.Options
      

      and it will show you the related records in Options. I don't know if the same Offres can have multiple Navire but if they do then this will show all Options from all related Navire.

       said:
      Maybe in the same script as the duplicate button, so in one shot I could duplicate a vessel and link its options to an existing offer or to a new one

      Ninox can't offer up choices from another table with in a script. That means you have to have all of the possibilities selected in fields then the script can do what you want based on data in fields.

      I'm guessing the current button is in the Navire table. Next to it you can create a second reference field to Offres. Ninox will probably call this reference field Offres2 since you already have a reference field to Offres. You can rename it to whatever you want. Why a reference field? It is more searchable then a dynamic choice and less overhead on the DB. Then you would modify your search to:

      let t := this;
      let newRec := duplicate(t);
      newRec.Offres := Offres2;
      for loop1 in t.Options do
       let newOp := duplicate(loop1);
       newOp.(
         Navire := newRec;
       )
      end;
      Offres2 := 0
      

      Of course modify it to match your table/field names.

      Line 3 is the new part that links the newly duplicated record to an Offres that you selected. If you don't select anything then nothing will get linked.

      Line 10 is added to unlink whatever is selected in Offres2 so it doesn't mess up any future linkage.

      • frsalabert.1
      • 1 yr ago
      • Reported - view

       Your script works fine, thanks. But I figure out what is my issue. It all comes from the printing template of my Offers. I can call the vessel’s record and its Options but the Navire.Options list do never show the “désignation” column (mandatory for the template I send to my client). Désignation is the name of the option, it is manage in the ‘Catalogue Options’ table. This one is linked to the Options table so I can manage different prices for one option. Then Options are linked to a record on the vessel Table. It is very convenient for me. But that way I am unable to call back the designation.’Catalogue Options’ on a table view with the prices in my printing template (I tried many way without success) - see screen shots- So to solve this issue I have imported in the offer table a table Offers to Options (1:N). This one is fully editable in the printing template, it works great. But each time, I have to link one by one all the vessel’s options to the offer (I hope it is clearer in the map table screenshots) to see them in the template. Reason why I look for a script which can duplicate a vessel and its options and link them to the Offers to Options table directly. It is a lot of infos but I hope you can more understand the situation…😮💨

    • Fred
    • 1 yr ago
    • Reported - view
     said:
    I have to link one by one all the vessel’s options to the offer (I hope it is clearer in the map table screenshots) to see them in the template. Reason why I look for a script which can duplicate a vessel and its options and link them to the Offers to Options table directly.

    Oh, yes the old print engine. I'm trying to learn the new Carbone print engine (dynamic printing). It is not easy, but not impossible. You might want to look into it. Especially the creation of json data so you can populate the print layout with just the necessary data.

    Ninox was asked if they were going to make a more user friendly print engine and the CEO said that they are happy with the Carbone solution and want to spend their time on the DB engine so don't hold your breath for any changes to the print engine.

    Along that route, what others have done in the past is what you were thinking about the Printing Template. What you would do is have a print button that would delete all previous records, then copy all necessary data from your data tables into new temporary records in the printing template. Then print from the Printing table. In your case there would be a child table to capture all the options.

    Now that I'm done with my babbling, a change to your code to do what you ask.

    let t := this;
    let newRec := duplicate(t);
    for loop1 in t.Options do
     let newOp := duplicate(loop1);
     newOp.(
       Navire := newRec;
       Offres := t.Offres2
     )
    end;
    Offres2 := 0
    

    This is still at the Navire table with a new reference field called Offres2.

    If you want to go back and do this to old Offres then at the Offres table you can add a button that has:

    let t := this;
    for loop1 in Navire.Options do
        Offres := t
    end
    
      • frsalabert.1
      • 1 yr ago
      • Reported - view

       Hi Fred! I did not fully understood the first option but the last one looks good to me. But I was not able to let it works: it looks like ninox do not recognize the Offres column (line 3). Indeed Offres is the table so I try 'N°Offre', tried 0ptions.'N°Offre' and many other, nothing happen. Any idea?

      • Fred
      • 1 yr ago
      • Reported - view

      oops, it should be:

      let t := this;
      for loop1 in Navire.Options do
          loop1.Offres := t
      end
      

      Sorry.

      • frsalabert.1
      • 1 yr ago
      • Reported - view

       Waooouuuu!!!! you're the best! Fred!

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 14Replies
  • 208Views
  • 3 Following