Page 1 of 1

Default Value of Select Field Equals Highest Value

Posted: Sat Aug 13, 2022 8:46 am
by neodaemon

I'm using 2022.12.2
I'm trying to set the default value of a select field to its highest possible value. The select field stores the ID of its lookup table.

This reference is from an old version and does not work:
viewtopic.php?p=103949&hilit=default+va ... id#p103949

...I think it has partially to do with the current PHP version having stricter parameter handling.

I have the select field results sorted DESC; which at least helps when selecting a value manually. But I would like the default value to appear in the field, and set to the highest possible ID which is stored in that field, and supplied by its lookup table.

Thanks in advance for any help or pointers in the right direction.


Re: Default Value of Select Field Equals Highest Value

Posted: Sat Aug 13, 2022 8:54 am
by mobhar

You may simply use Row_Rendered server event to do this.

Just use ExecuteScalar global function to get the single highest value in that Select field, after that, just assign that value to the CurrentValue property of the field. Please try it by yourself first, and you may post your code for more discussion.


Re: Default Value of Select Field Equals Highest Value

Posted: Sat Aug 13, 2022 11:13 am
by neodaemon

This failed, probably because I am a poor coder. Following is my code:
$myField = ExecuteScalar("SELECT max(eventid) FROM events");
$this->eventid->currectvalue == $myField;

The error I get is:
Warning: Undefined property: PHPMaker2022\gman2022\DbField::$currectvalue


Re: Default Value of Select Field Equals Highest Value

Posted: Sat Aug 13, 2022 11:23 am
by arbei
  1. Property name is case-sensitive (Method name is case-insensitive though).
  2. Use assignment operator "=", not "==" which is comparison operator.

Re: Default Value of Select Field Equals Highest Value

Posted: Sat Aug 13, 2022 11:31 am
by neodaemon

Thanks for the tip. After following those two pointers it worked.
Thanks again,