0

Create record in another table on a switch

Hi all,

Bear with me as I'm a new user and don't have any tech / db-skills. If the answer to my question is in another post, please show me a link. I've tried to search the topics, but can't find my answer.

This is the situation:

I have a table [Uren] with a switch per record. Yes or No.

If I make a new record in this table [Uren] and set the switch on "Yes", I want to, automatically create a new record in another table [Reiskosten]. This record should have the same date as the record I was working on in [Uren].

This is my main question, but if possible I would also like to copy another field / link into this new record. This field is a field form yet another table [Klanten]. I have to hand-pick this now.

Hopefully I can clearify the situation with this pictures:

So when I make a record in [Uren] I select a record from table [Opdrachten] and it gives me the {Klant} which is linked to table [Klanten] (there's a link between the table [Opdrachten] and the table [Klanten]).

If {Op locatie}=Ja (Yes), I want to make a new record in [Reiskosten] with the same date as in [Uren] and the same {Klant}.

 

Hopefully someone can explain what tot do, so I can learn.

Thanks  

4 replies

null
    • Fred
    • 2 mths ago
    • Reported - view

    Welcome to Ninox.

    If I make a new record in this table [Uren] and set the switch on "Yes", I want to, automatically create a new record in another table [Reiskosten]. This record should have the same date as the record I was working on in [Uren].

    You will eventually be using the Trigger after update part of the Yes/No field (Op locatie?). Since you will be learning some new things you may want to create a button in Uren first so you can test out your code before putting it in the trigger.

    In the button write:

    let t := this;
    let newRec := create Reiskosten
    newRec.(
        Datum := t.Datum
    )

    Line 1, we create a variable called t that uses the special Ninox word 'this' to capture record Id of the current record we are on.

    Line 2, we create a variable called newRec and use the command create to create a new record in Reiskosten.

    Lines 3-5, we use that variable from line 2, to then modify the newly created record by copying the data from Datum in Uren (by using the variable 't') to the Datum field in the newly created record in Reiskosten that is represented by the newRec variable.

    You can add other fields below Datum by adding a comma then add the new field.

    let t := this;
    let newRec := create Reiskosten
    newRec.(
        Datum := t.Datum,
        field2 = t.field2,
        etc
    )
    

    but if possible I would also like to copy another field / link into this new record. This field is a field form yet another table [Klanten]. I have to hand-pick this now.

    Klanten is a reference field in Reiskosten. Since we have just created a new record in Reiskosten, Klanten is empty. The question now is how to link the new record to a record in Klanten? Using fields in Reiskosten how would figure out which record in Klanten to link to?

    • lind
    • 2 mths ago
    • Reported - view

    Hi Fred,

    Thanks a lot for your response. I just found out how to make a button :) so now I'm trying the rest of your solution.

    I'll come back later to answer your question about the Klanten. But just wanted to let you know that I've read your post and working on it.

    Grtz.
    Linda

    • lind
    • 2 mths ago
    • Reported - view

    Whoohoo! Your solution (with the button at least) worked (I wasn't doubting it, but it's nice to see that it worked).
    But now I need the next step,  I only want to make a new record if I set the switch on Yes. Is this also possible? If yes, how do I do that?

     said:
    Klanten is a reference field in Reiskosten. Since we have just created a new record in Reiskosten, Klanten is empty. The question now is how to link the new record to a record in Klanten? Using fields in Reiskosten how would figure out which record in Klanten to link to?

    Klanten is a reference field in Reiskosten. But Klant(en) has a link in the table: Opdrachten.
    So when I make a new record in Uren, I choose a record from Opdrachten. Which has a reference to Klanten. That's how Reiskosten can know which Klant to link to. I think :).

    So I input the name of the company in Klanten and I link this company in the table Opdrachten to a record.

    • Fred
    • 2 mths ago
    • Reported - view
     said:
    Klanten is a reference field in Reiskosten. But Klant(en) has a link in the table: Opdrachten. So when I make a new record in Uren, I choose a record from Opdrachten. Which has a reference to Klanten. That's how Reiskosten can know which Klant to link to. I think :).

    Ok, you can try:

    let t := this;
    let newRec := create Reiskosten
    newRec.(
        Datum := t.Datum
    Klanten := t.Opdrachten.Klanten
    )

    Assuming it is a 1:N (1 to many) relationship between Klanten and Opdrachten, you see a field to select a single record in Klanten while in Opdrachten.

Content aside

  • 2 mths agoLast active
  • 4Replies
  • 58Views
  • 2 Following