0

illusion of Inserting new lines into middle of child table ((invoice/order/quote) lines)

I have been looking at the issue of child tables when used within say invoice/order/quote body.

I have parent table (Quotes) and child table (QuoteLines)

Each quote may typically have between 1 to 10 child lines per quote. The child table (quote lines) is being sorted ascending on the internal Ninox ID both visually on screen and indeed on the print layout out (PDF) that gets issued to the client

This works fine until I wanted to add in a similar line to one of the lines already entered and have it show in position both on screen and on the print out! - ie

Line 1 Red pens printed in white x 500

Line 2 Blue pens printed in white x 1000

Line 3 Screens setup cost

Line 4 Carriage to one uk location

Line 5 Blue pens printed in white x 500 (this is the new line added after the quote initially done and clearly needs to between line 1 and 2) This coulf have been missed out at input time in error or the cliend does the usual - oh can you ad me etc......

The usual Ninox sorts are on this occasion not much use ie by description etc as this throws all the body visiually out! and sorting by the Ninox Id is no longer appropriate - So another field needed to be introduced (ie ‘QLnum’ - Quotes line order and is a number field) I inserted the following code on the table trigger on create!

let myQLN := max((select QuoteLines).QLnum); QLnum := myQLN + 2

Which gives me line numbers in incremental steps of 2 (1-3-5 etc.)

Thus I can simply change the newly added  line entry to say 2 and then my new line will sit within the position I need it. Better still was to make QLnum fixed at 1 dec place. 2.0-3.0 etc and that now gives me up to 9 lines of insert! 2.0 - 2.1 - 2.2 etc.

So okay onto my the issue

QLnum will forever keep adding numbers and the quote lines body will quickly get up to line 1501 etc. So I wanted a way to reset QLnum after x number of lines.

let myNum := last((select QuoteLines).QLnum); QLnum := 1 + myNum - floor(myNum / 10) * 10

The above partially solves my issue as I can now control the line number generation to x numbers and reset it after every 10-50-100 etc. Again great

But quote number 1 might have 6 lines and quote number 2 might have 11 lines

Thus I would end up quotes would have child lines that get reset part way through (not ideal)

So what I would like to do is reset the QLnum (quote body lines) back to 1.0 for every new quote generated

and then do my stepping of numbers as above to allow my inserts when and if required.

But just can’t quite get my head around this as I need the child table numbering to detect when a new parent table quote has been started.

Any suggestions ?

Also do you agree /disagree that the above stepping of numbers on an internal number field is practical/sensible or has any one got a better or more elegant suggestion?

Thank you in advance

 

 

6 replies

null
    • Mel_Charles
    • 3 yrs ago
    • Reported - view

    I suppose I could do a test on creation of the parent table 'Quotes' to test if no sub records (child's) exist then reset QLnum to 1

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    Hint:

    This: max((select QuoteLines).QLnum) gives the largest value of QLnum in the entire QuiteLines file.

    This: max(QuoteLines.QLnum) should give the largest value of QLnum among the records linked to the current record in Quotes, or "0" if there are no linked records.

    • Mel_Charles
    • 3 yrs ago
    • Reported - view

    Sorry Alain

    I'm just not getting this to work

    any chance you can expand on your hint to show me the way please

    on either method below

    let myQLN := max((select QuoteLines).QLnum); QLnum := myQLN + 2

    or

    let myNum := last((select QuoteLines).QLnum); QLnum := 1 + myNum - floor(myNum / 10) * 10

    I'm coming to Ninox from 35 years of dataese precedural scripts

    and guess what dataease has a numberic sequence field buit in.

    thus dataease script would be 

    for Quotes with qteNum = current record ;

    modify all Quotelines qteNum sequence from 0001.

    done !

    • Alain_Fontaine
    • 3 yrs ago
    • Reported - view

    In the "Quotes" table, you should have a reference field (1:N) named "QuoteLines". In the "QuoteLines" table, you should have a reference field (N:1) named "Quotes" (if you did not rename those fields after the creation of the reference).

    By putting the formula below as the "Trigger after update" of the "Quotes" reference field in the "QuoteLines" table, the lines of each quotes will be numbered, starting with 10, and adding 10 at each line (why would one only add 2 when you can add 10 for the same price?).

    QLnum := max(Quotes.QuoteLines.QLnum) + 10

    If there is a need to renumber the lines after some additions, a button in the "Quotes" table with the formula below will do the trick.

    let Zcnt := 10;
    for Zql in QuoteLines order by QLnum do
         Zql.(QLnum := Zcnt);
         Zcnt := Zcnt + 10
    end

    • Mel_Charles
    • 3 yrs ago
    • Reported - view

    Alain

    Ah I see where I was going wrong. I was putting my script in the trigger on create in the subfile (child) table it self! ie quote lines.

    This worked for the line number generation but for the life of me I could not get it to regenerate starting from effectively 1 for each new quote !!!

    Did not think to put the script in the relationship link it self - Live and learn !!!

    Your code worked first time !!!

    Thank you sir!

    • Mel_Charles
    • 3 yrs ago
    • Reported - view

    Just to report back on this 
    i have no gone on to to use this code on a button to post several fields into a child table and either overwrite the suggested value or accept that value offered. Code is now on that button!.

    So my example of invoice/quote or order line has the entry fields on main form "Quotes" (Parent) the button posts th eline entry into child form ("quote lines") and also with Alain's excellent suggestion of re indexing the line numbers - This gives me excellent results.

    Alain - your the man :-) 

Content aside

  • 3 yrs agoLast active
  • 6Replies
  • 723Views