This topic is locked
[SOLVED]

 Default value

5/31/2020 10:29:28 PM
PHPRunner General questions
rdf author

Hi PHPR community,
I have a Add form with the following field:
Form number: (It will be prefixed by either C or P depending on what is chosen on the System field). Example format C20001
System: (Choices are C or P)
The Fields->Field Properties->Default Value can be a simple way to do this but I can't seem to find a way to use PHP in getting the control value on the System field.
I am able to do this with JavaScript Field Events and Add Page Event. But Fields->Field Properties->Default Value is probably the simpler solution.
Thank you.

rdf author 6/1/2020



Check this for inspiration:

https://asprunner.com/forums/topic/14732-generate-a-custom-transaction-number-for-example-so20100700001/


Hi Sergey,
That is great. Thank you for the link.
The auto-incrementing logic is useful but I will use it on the year part instead since my form number format is: [C|P]yyxxx (C20001).
I will see how I can implement the prefix "C" or "P" on the form whichever the user select on the dropdown list in the Add form.

rdf author 6/2/2020

Hi,
Just want to include on what I did to get the same result from the link provided by Sergey but by using the 2-digit year instead of the month. This is on the Before Record Added event. I added a Date field just for testing purposes so I can change date using other years:



$sql = "SELECT MAX( SUBSTR( SO_ID, 5 ) ) AS mx FROM SALES_ORDER WHERE SUBSTR( SO_ID, 3, 2 ) = SUBSTR(" . "'" . $values[ 'DATE' ] . "'" . ", 3, 2 ) ORDER BY mx";

$rs = DB::Query( $sql );

$data = $rs->fetchAssoc();

$str = "SO";

$str2 = substr( $values[ 'DATE' ], 2, 2 );

$str3 = ( $data[ "mx" ] + 1 );

$values[ "SO_ID" ] = "$str$str2" . str_pad( $str3, 3, 0, STR_PAD_LEFT );
rdf author 6/2/2020

Hi community,
Just one thing about this solution in maintaining a form number.
For example you have these form number:

SO20001

SO20002

SO20003

SO20004

SO20005
and, you delete SO20005, when you enter another record, since SO20004 is the last entry, it will increment it to SO20005.
Probably there is a much better implementation for creating a form numbering solution.