0

coding for create record

Hi,

When I click the +Create Record in a referenced table, I get a new record in which the client code (a unique code) is filled in as is the link which the parent (client) table.

When I try to recreate that with a button, I cannot seem to get that to work. I browsed the forum but all suggestions don't work with me.

For some context: I have a main client-table. For each client I have a session-table with multiple session per client, and a similar invoice-table (which is also linked to the session- and client-table). It's not possible to create a session-record without a client-record nor an invoice-record without a session-record. I only use the app local. 

What I'm looking for is this:

I need to create a new record in Sessions (with client-ID, client-Name automatically filled from the client record and a link to the main client-table) with a button in the client-table. I need this only for the first session so the session-number can be filled as well. There must be an easy solution but I cannot find it.

Everything I tried only gave me a new record in the session-table without all the necessary fields filled or the link with the parent-table. I can only get the session number to be filled with what I want it to be filled with.

In addition: I'm looking for a way to link the reference tables automatically when I make a new invoice-record from the Sessions-table. Just clicking a + to create a new invoice in the invoice-table only links it to the session-table and not the main client-table.

Who can help me?

20 replies

null
    • Fred
    • 2 yrs ago
    • Reported - view

    Can you post the code?

    • mpm
    • 2 yrs ago
    • Reported - view

    Which of the variations do you want me to post? 馃槈

    This was the latest:

    let a := ID;

    let k := number(Sessies.ID);

    let n := text(Voornaam);

    let vn := text(Sessies.Naam);

    let i := (create Sessies);

    i.(k := a);

    i.(vn := n);

    i.('S-nr' := 0);

    openRecord(i)

     

    I tried with let a:=Coachees.ID (and let n:=text(Coachees.Voornaam);) and tried with (create Sessies).(k := a). The only thing that works is Create, openRecord and i.('S-nr' := 0)

    • Fred
    • 2 yrs ago
    • Reported - view

    It is a bit of a slog through the forums to find what you need.

    Question: are there fields with the names of 'k' or 'vn' in the table Sessies? If these are references to the variables created above then that is probably why it is not working. You need to reference the fieldnames in Sessies when you are using the create command.

    You can try the following:

    let a := this;
    let i := (create Sessies);
    i.(
    referencefieldname := a;
    Naam := a.Voornaam;
    'S-nr' := 0
    );
    openRecord(i)
    

    Line 1: instead of ID, you should use 'this'. If you wanted to use the Ninox record number then it is Id. I find 'this' more flexible, as you can see in the following lines.

    Line 4: you need to change this to the reference field name in Sessies that points to your main client table. In line 1 we linked the Ninox record to 'a' so we can just point to 'a' to link the records.

    Line 5: is my best guess at the field name in Sessie that you want to link to Voornaam. You can see here that I'm using the variable 'a' and then adding the field name that I want to use. If I'm wrong then change to the appropriate field names.

    Also you can see that I've removed the individual reference to 'i' before each field you want to modify. This format allows for quicker changes in the future.

    • mpm
    • 2 yrs ago
    • Reported - view

    Hi Fred,

    Thank you for your response. I tried but the referencefieldname keeps giving an error with that it isn't a date field. (I worked out how to remove the Naam field so that is gone). This is what I made of the button:

    let a := this;
    let i := (create Sessies);
    i.(
    Nr := a;
    'S-nr' := 0
    );
    openRecord(i)
     

    Because of the field data error, I previously found it had to do with the type of field. So: the Coachees.ID is a number, so I changed the function Sessies.ID ( which was =Coachees.ID) to a number as I did before. So Sessies.Nr (=number(Coachees.ID)) is a number also and at the same time I removed the ID and Id clash. That didn't work either.

    The error "Field is no data field" I kept having on all my previous attempts on making this code work. Always on the same line: the line with the unique ID.

    • mpm
    • 2 yrs ago
    • Reported - view

    It's frustrating because clicking the +Create Record (in another TAB) works just fine ...

    • Fred
    • 2 yrs ago
    • Reported - view
    mpm said:
    I need to create a new record in Sessions (with client-ID, client-Name automatically filled from the client record and a link to the main client-table) with a button in the client-table.

     What is the name of the field in Sessies that points to Coachees? Put that in place of the referencefieldname.

    • mpm
    • 2 yrs ago
    • Reported - view

    I did. The name is Nr and that field points to Coachees by being the same as the Coachees.ID.

    • Fred
    • 2 yrs ago
    • Reported - view

    What kind of field is 'S-nr'?

    Can you try this simplified code?

    let a := this;
    let i := (create Sessies);
    i.(
    Nr := a
    );
    openRecord(i)
    
    • mpm
    • 2 yrs ago
    • Reported - view

    S-nr is a number field. I use it to number the sessions per client and to make a unique session code with the sessies.nr.

    I tried your suggestion earlier (and just now again) but it still gives the same error: "Field is no data field" on line 4. Just the := is underlined in red.

    • Fred
    • 2 yrs ago
    • Reported - view
    mpm said:
    I tried your suggestion earlier (and just now again) but it still gives the same error: "Field is no data field" on line 4. Just the := is underlined in red.

     So 'Nr' is not the reference fieldname to Coachees. Nr is a formula field that is why you are getting that error. In Ninox you create a link in Edit Fields then select Table References then drag the name of the table over. Did you create a field this way? If so then use the name of the field.

    • mpm
    • 2 yrs ago
    • Reported - view

    I did as you described: I dragged the Sessies table into the Coachees table ("Reference from Coachees to Sessies (1:N)").

    The Sessies table must be linked in the correct way because when I click +Create Record in the Sessies table (which I have in a separate tab in the Coachees form), it makes a new record in the Sessies table with the Coachees.ID in the Sessies.Nr field.

    That's why I want to know the code from the +Create Record in the reference table so I can make a button in the first tab just to fill in the date of the first (intake) session. I don't want all the sessions of that particular client displayed on the first tab.

    • Fred
    • 2 yrs ago
    • Reported - view
    mpm said:
    it makes a new record in the Sessies table with the Coachees.ID in the Sessies.Nr field.

     So now you put the name of the reference field link in the Sessies table, probably called Coachees.

    • mpm
    • 2 yrs ago
    • Reported - view

    Sorry, I lost you. Coachees is a table name, not a field name. I have no specific field that connects the two and I haven't found how to do that (before your reply I didn't know that was needed). Probably the 1:N but I don't know which fields they are, they are automated by Ninox when I dragged the Sessies table into the Coachees table.

    When I create a record from the Coachees table into the Sessions table (with the +Create Record), the formula for Sessies.Nr is number(Coachees.ID) and that is put in. So that's my link between the two tables.

    Btw: I removed the : in the Nr := a line and there was no error but the new record doesn't get the so needed Coachees.ID and there is no link to the Coachees table from which it originated.

    • Fred
    • 2 yrs ago
    • Reported - view
    Marjolijn said:
    I dragged the Sessies table into the Coachees table ("Reference from Coachees to Sessies (1:N)").

    So what is the field name of the field you describe?

    Another way is, in the Sessies table do a Edit Fields and look for the field with an arrow pointing to the left. That is the name of the reference field to Coachees. Unless you have multiple reference fields. Then you need to find the one that points to Coachee with the same text as from the quote above.

    If you can, post a copy of your db with sample data.

    • mpm
    • 2 yrs ago
    • Reported - view

    Hope this helps. I made one test coachee. The button "Maak intake" (first tab in the Coachees table) is the one I need but doesn't want to work.

      • Ninox partner
      • RoSoft_Steven.1
      • 2 yrs ago
      • Reported - view

      Marjolijn 

      Hoy Marjolijn,

      Enkele fouten in uw code, dit zou het moeten worden in uw knop:

      let a := this;
      let i := (create Sessies);
      i.(Coachees := a);                  -----<Hier stond i.(Nr = a)
      openRecord(i)

       

      Aangezien Nr en formule veld is kan dit niet worden ingevuld, ook het = teken is om iets te vergelijken := is om iets toe te wijzen.

      Steven

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

      RoSoft_Steven thank you Steven! This worked for me as well

    • mpm
    • 2 yrs ago
    • Reported - view

    hoi Steven,

    Getest en het werkt helemaal super! Dank je!

    Tested and it works absolutely super! Thank you!

    • mpm
    • 2 yrs ago
    • Reported - view

    To the second part of my initial question: might someone now if there is a way to link the reference tables automatically when I make a new invoice-record from the Sessions-table. Just clicking a + to create a new invoice in the invoice-table only links it to the session-table and not the main client-table.

    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view

    Marjolijn

    If you want to create a new invoice in your sessies table, add a button with this code:

    let c := Coachees;
    let s := this;
    let newFact := (create Facturen);
    newFact.(
        Sessies := s;
        Coachees := c
    );
    openRecord(newFact)

    This creates a new invoice and links the Sessies and also the coachees.

Content aside

  • 1 yr agoLast active
  • 20Replies
  • 345Views
  • 4 Following