0

Help with relationship

Hi everyone so I have two tables 'Claims' and 'EntryLog' there is a many-to-one relationship between them (many EntryLogs to one Claim).

Every time I put in a payment for a claim in my Claims table and click Update-(which is a button), the 'Claim ID', 'Payment amount', 'Date paid', 'Paid from' fields are copied over in EntryLog table with the code below:

let aPlaced := 'Amt Placed:';
let aPaid := 'Amount Paid';
let lpoClaim := 'Last Payment on Claim:';
let dPay := 'Date of Payment';
let pTo := 'Paid To:';
let pFrom := 'Paid From';
let cID := 'Claim ID';
let cDate := 'Claim Date';
let cName := 'Creditor:';

let newLog := (create EntryLog);

newLog.(Payment := aPaid);
newLog.(Payment_Date := dPay);
newLog.(Paid_To := pTo);
newLog.(Paid_From := pFrom);
newLog.(Claim_ID := cID);
newLog.('Date of Claim' := cDate);
newLog.(Creditor_Name := cName);

 

I am trying to create a formula field in my Claims table that would give me a total payment of the claims that I am currently on and hopefully another formula field that would show me the remaining amount I have to pay? However I can't seem to get a return value from the EntryLog>Payment field.

I was wondering if its the relationship but I am not sure. Any help would be greatly appreciated my fellow developers.

5 replies

null
    • Fred
    • 7 days ago
    • Reported - view

    You probably aren't seeing the reference table EntryLog in Claims filling up as you press the button.

    I don't see the line where you link the new EntryLog record with the current Claim record. Sadly Ninox does not automagically link the records. By default Ninox would have created a reference field in EntryLog called Claims. So using that name you need to add two lines:

    let t := this;
    -previous lines-
    
    newLog.(Claims := t);

    If you renamed it then please update the name.

      • Nicholas_Daniel
      • 6 days ago
      • Reported - view

       Thanks for the reply Fred, so I added the lines to the button

      let aPlaced := 'Amt Placed:';
      let aPaid := 'Amount Paid';
      let lpoClaim := 'Last Payment on Claim:';
      let dPay := 'Date of Payment';
      let pTo := 'Paid To:';
      let pFrom := 'Paid From';
      let cID := 'Claim ID';
      let cDate := 'Claim Date';
      let cName := 'Creditor:';
      let t := this;

      let newLog := (create EntryLog);

      newLog.(Payment := aPaid);
      newLog.(Payment_Date := dPay);
      newLog.(Paid_To := pTo);
      newLog.(Paid_From := pFrom);
      newLog.(Claim_ID := cID);
      newLog.('Date of Claim' := cDate);
      newLog.(Creditor_Name := cName);
      newLog.(Claims := t);

      To be honest, I'm not exactly clear on what you explained that the lines would do. 

      I also added a formula field to my Claims table named 'Total' and I would like it to group all the payments made grouping them by their Claim id's so I added this code to the field:

      sum(select EntryLog where Payment = this)

      But it is only returning $0.00

      Could you figure our what I am doing  wrong? I am attaching some photos for you to better understand.

    • Fred
    • 6 days ago
    • Reported - view

    What happens when you use the create() command is that Ninox creates a new record like if you went to that table and clicked on the + sign. You have a new record with empty fields. Now you need to link this new empty record to the Claims record you are on.

    So first we need to put the current record you are on into a variable. So line 1, we use the this command to get the current record Id into a variable, the letter t. Then on line 3, you create a new record in EntryLog and put that into the variable newLog. The first thing I do, is then link the record new record with my current record, line 5.

    In you second picture, that show E_Log, I see that Claims1 is the name of the reference field to, I guess, the Claims table, if this is not true then you need to make sure you use the name of the reference field. So this is name you need to add to your newLog.

    let t := this;
    
    let newLog := (create EntryLog);
    newLog.(
        Claims1 := t;
        Payment := t.'Amount Paid';
        Payment_Date := t.'Date of Payment';
        Paid_To := t.'Paid To:';
        Paid_From := t.'Paid From';
        Claim_ID := t.'Claim ID';
        'Date of Claim' := t.'Claim Date';
        Creditor_Name := t.'Creditor:';
    )

    By using the this command, you have access to all of the fields in the record through the variable. So I've cleaned up the code to show how it can be written.

    I also added a formula field to my Claims table named 'Total' and I would like it to group all the payments made grouping them by their Claim id's so I added this code to the field:

    sum(select EntryLog where Payment = this)

    Your code will not return anything because the this command returns the record ID of the current record. Plus it can only used in limited circumstances, like in setting a variable. So almost all of my code has the same line 1:

    let t := this;

    I'm guessing you only want to find the total payments of related records. By using the select and only looking at Payments you will get all EntryLogs with the same Payment regardless of which claim it belongs to.

    We want to use the power of a relational database that is Ninox. Since you have a M:1 relationship between EntryLog and Claims. Once you solve how to link records in a button, you can simply do something like:

    sum(EntryLog.Payments)

    in a formula field.

    If you continue to have issues, please post a sample DB (with no personal information) to the forum.

      • Nicholas_Daniel
      • 4 days ago
      • Reported - view

       My new found friend hiding behind the name Fred 😄😉 I finally got through with the two tables relating through the 'this' command. Thank you sir for being patient with me and teaching me, I appreciate you very much.

      • Fred
      • 3 days ago
      • Reported - view

       When you get a moment, please mark the post answered. :)

Content aside

  • Status Answered
  • 3 days agoLast active
  • 5Replies
  • 43Views
  • 2 Following