0

How to auto-fill the relationship field choice?

How to auto fill this relationship field when I create new record, instead of click into the field and choose what record. I want it auto fill because the date is just the latest date, so I don't have to click on it 2 times. can someone help me with this please?

28 replies

null
    • Fred
    • 8 mths ago
    • Reported - view

    If the table NGAY THU/CHI has a date field called Date then you can test it out in a button with:

    let selectNGAY := first(select 'NGAY THU/CHI' where Date = today())
    'NGAY THU/CHI' := selectNGAY

    Line 1, does a select statement that goes to the table NGAY THU/CHI (assuming that is the name of the table as well) and finds all records where the Date field equals today’s date. Then you have to use the first() command, even if you only return 1 record, so Ninox only has 1 record to work with.

    Line 2, sets the reference field ‘NGAY THU/CHI’ to the record found in line 1.

    • Nguyen_Nhat_Dong
    • 8 mths ago
    • Reported - view

    I have try but it not work it said: 1. Ngay Thu/Chi is not found, line 1 collum51

    2. symbol expected, line 1 collum51

    3. unexpected keywork, line 1 collum 56

    4.End expected, line 1 collum 56

      • Fred
      • 8 mths ago
      • Reported - view

      Remember, I do not know anything about your DB, so I'm just guessing.

      1) what is the table name that the Reference filed 'NGAY THU/CHI' points to? Put that table name after select.

      2) What is the field name that stores the date value? Put that in place of Date.

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       1. The table name called : "THU/CHI"

      2. The field name is 'NGAY THU/CHI'. NGAY. but when I put in it error. it said : 

      1.Field not found: NGAY THU/CHI at line 1 collum 61

      2. Expression does not return a record: 'NGAY THU/CHI'  at line 1, collum 62

      • Fred
      • 8 mths ago
      • Reported - view

      Can you upload a copy of your DB with test data?

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       sorry how can I do that?, I am just a newbie, First time hearing uploading a database with test data.

      • Fred
      • 8 mths ago
      • Reported - view

      Which version of Ninox are you using? Cloud or app? If cloud which level?

      If you DB doesn't have any personal identifiable data then you can skip this step, but if you do then you should make a duplicate DB that does not have any personal data.

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       I am just creating for like 2 weeks, and I don't have any DB on this version.

      • Fred
      • 8 mths ago
      • Reported - view

      How are you using Ninox? In a browser or in the app?

      if the app which version (MacOS, iOS, Android)?

      if in the browser, what level did you purchase?

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       I am using an browser, I am purchasing a starter package

    • Fred
    • 8 mths ago
    • Reported - view

    In the Shipping table, you can add a button with the following code:

    let selectNGAY := first(select 'THU/CHI' where NGAY = today())
    'NGAY THU/CHI' := selectNGAY
    

    This is link the first record in THU/CHI that has today's date to the current record in Shipping.

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       it is not working. I tried to put the code in the "trigger on new record", and I also tried to create a button in the shipping table, but when I click on it, it not working for some reason.

      • Fred
      • 8 mths ago
      • Reported - view

      take a look in the THU/CHI table. what is missing?

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       wait it is working now. How did you do that? What did you change tho?

      • Fred
      • 8 mths ago
      • Reported - view

       I didn’t do anything. 
       

      I asked you a question. The code looks to the THU/CHI table and tries to find records where the NGAY field equals today. So if you look at the table what is missing?

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       anyway, it is working. now can I use the same code for relationship field CHUYEN HANG? like:

      let selectNGAY := first(select 'THU/CHI' where NGAY = today());
      'NGAY THU/CHI' := selectNGAY
      let selectCHUYEN := first(select 'CHUYEN HANG' where NGAY DI HANG > today())
      'CHUYEN HANG' := selectCHUYEN

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       The Date for CHUYEN HANG It always be the lastest record.

      • Fred
      • 8 mths ago
      • Reported - view

      Now comes the fun part. Take the bit you have learned and try to do different things.

      You wrote:

      select 'CHUYEN HANG' where NGAY DI HANG > today()
      

      Will you have records where the date in NGAY DI HANG is greater than today?

      Let us know how it goes.

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       Yes, I tried this but it said: 1. End expected: let at line 3 collum 3.

      • Fred
      • 8 mths ago
      • Reported - view

       

      In Ninox, you end commands with a “;”.

      So lines 2 & 4 need what?

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       I SEE, EVERYTHING WORK PERFECTLY, THANKS YOU SO MUCH.

      • Fred
      • 8 mths ago
      • Reported - view

      If you are satisfied with the answer please mark the post answered.

      • Nguyen_Nhat_Dong
      • 8 mths ago
      • Reported - view

       Sure thanks fred.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 8 mths ago
      • Reported - view

       Hi Fred.

      I have some similar situation.

      On Table 1 I have a 'Name Document' text field.

      On Table 2 I have a 'Document_>'  Relation field N:1 to Table 1.

      I Need when  type the Name Document on Table 1 update on Table 2 in the N:1 field 'Document_>'

      Thanks

      • Fred
      • 8 mths ago
      • Reported - view

      Can you post what you have so far?

Content aside

  • Status Answered
  • 8 mths agoLast active
  • 28Replies
  • 180Views
  • 3 Following