1

Button for create a new record which has a connection to a record

I have a table, where in every record, i have a connection of records from a different table showing up.  (1:N)
when want to get a new record, normally click "+ Neuer Datensatz" at the 1:N, and there i get a new record, which already has automatically a connection to the table. But then i use a button with the code:

create TableName

it just gives me a new record, but no connection to the table i am in.

 

12 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    You can check out this post.

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

      Fred thank you! My problem is just, i cant understand how i can apply this what i need, from this other post. Can you help me on that?

    • Fred
    • 1 yr ago
    • Reported - view

    I can try.

    You have a good start with:

    create TableName
    

    The issue you are encountering is you have not specified the record to link to the new record in TableName. Since I don't know the structure of your DB, let us start with the following:

    2 tables - Table1 and Table2

    Table1 is your main table with a 1:N relationship to Table2. There is a field in Table2 called 'linktoTable1' which is the reference field to Table1. It is not just a plain text field.

    So in Table1 we create a button with the following:

    let t := this
    let newRec := (create Table2)
    newRec.linktoTable1 := t
    

    Line 1 creates a variable t that stores the Ninox recordId of the current record.

    Line 2 creates a variable that first creates a new record in Table2.

    Line 3 then takes that new record in Table2 then links the reference field 'linktoTable1' to the record that stored in the variable t.

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

      Fred Very great explained! Thank you very much!

      • Michael_Blechinger.1
      • 2 mths ago
      • Reported - view

       i thank you very much! Somehow i just started to understand the code just now. And it works! 
      I have 2 more things to ask:

      1) You have an idea how to give to a another or multiple fields of table 2 some specific values? Now i just added to one field some value.

      2) And then I would like to Popup this record. I just worked it out using last(), but maybe there is a different way to do it.

       

      let t := this
      let newRec := (create Studypoints)
      newRec.(StatsWoche := t);
      popupRecord(last(select Studypoints));
      
      • Fred
      • 2 mths ago
      • Reported - view

       to modify other fields in the newly created record you do:

      let t := this
      let newRec := (create Studypoints)
      newRec.(StatsWoche := t;
          field2 := t.field2;
          field3 := t.field3);
      popupRecord(newRec);
      
      

      If you want to pop up the record you just recreated then just reference the variable of the new record.

      • Michael_Blechinger.1
      • 2 mths ago
      • Reported - view

       Thank you so much!! Its so simple :-)

      • Michael_Blechinger.1
      • 2 mths ago
      • Reported - view

       is there also a way, after pop up the record, to open some N:1 field to get the pop up to search the matching record, which will be selected manually. I want to reduce any mouse-clicks with this script.

      • Fred
      • 2 mths ago
      • Reported - view
       said:
      is there also a way, after pop up the record, to open some N:1 field to get the pop up to search the matching record, which will be selected manually. I want to reduce any mouse-clicks with this script.

      I don't understand what you are asking? Please break down the question into steps so I can try to figure out the process.

      • Michael_Blechinger.1
      • 2 mths ago
      • Reported - view

       I am sorry, i will simplify it:

      After this script, i have created a new record and also has popup-ed and now i would like that this field (in the screenshot) is opened to search. Like as i would click on the magnifier. The script should replace the action of clicking it with the mouse.

      • Fred
      • 2 mths ago
      • Reported - view

      To the best of knowledge there is no way to tell Ninox to go to a specific field in a form.

      • Michael_Blechinger.1
      • 2 mths ago
      • Reported - view

       I just have the idea, that maybe there is a way with javascript, but using GetElementById and then trigger this element with a simulated mouseclick.

Content aside

  • Status Answered
  • 1 Likes
  • 2 mths agoLast active
  • 12Replies
  • 536Views
  • 2 Following