Announcement

Collapse
No announcement yet.

How to prime a field on insert - from another table value

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to prime a field on insert - from another table value

    Hi All,

    I wish to prime a new invoice "master" record with an invoice number. Because normal auto increment is not possible in this case, I have the value of the last invoice number stored in a single record table.

    Where in the form events would I run a select statement to get that value, so that I can then prime the form field with the next number. I have tried the logical ones OnApplicationInit and OnScriptInit and Load and OnBeforeInsert but they all return a blank.

    The sc_lookup select statement works OK, I have tested that, but I do not know where the priming actually takes place.

    Thanks

    Tony

  • #2
    onLoad should be fine. How are you trying to assign the value?

    If the value you pulled from a query is in $number, say - then you should be able to assign it to the field {invoicenum} via (checking it's empty already, i.e. a new invoice):

    Code:
    if (trim({invoicenum}) == '') {
    	{invoicenum} = $number;
    }

    Comment


    • #3
      Brilliant, it worked. I originally set the initial value field, in the field settings section, to the $number but that failed me. Your code has worked a treat.

      Thanks

      Tony

      Comment

      Working...
      X