Page 1 of 1
Auto-generated string structure
Posted: Fri Jul 21, 2017 2:24 am
by Laim71
Hi,
Can someone who has a working code help me.
I'd like to auto-generate a user submitted tickets codes.
The structure I want is DI-0001...n.
"DI-" is the constant part; "000x" wil grow incrementing by one unit according the last number used.
The field which contains the number is named "N°DI"
The field which contains the generated code is named "CodeDI"
THANKS
Re: Auto-generated string structure
Posted: Fri Jul 21, 2017 12:17 pm
by arbei
To create the default value of the ticket code with below steps.
Get the max from the field "N°DI" with ew_ExecuteScalar().
e.g.
$maxid = ew_ExecuteScalar("SELECT MAX(<Field>) FROM <TABLE>");
Calculate the new ID
e.g.
$newid = maxid + 1;
Construct the ticket code using str_pad() PHP function then use it as the default value in Row_Rendered Server Event.
For example:
if (CurrentPageID() == "add")
$this-><Field>->EditValue = <New Code>;
Read help file topic: "Server Events and Client Scripts" -> "Some Global Functions" for more information.
Re: Auto-generated string structure
Posted: Thu Jul 27, 2017 3:01 am
by Laim71
Hi,
This is my last code In Page Render event
$bcode="000";
$maxid = ew_ExecuteScalar("SELECT MAX("IDDI") FROM t_di");
$newid = $maxid + 1;
$code=str_pad("$bcode", 4, $newid, STR_PAD_RIGHT);
1 - Is it the right place to ru it?
2 - Could you check my logic.
THANKS
Re: Auto-generated string structure
Posted: Thu Jul 27, 2017 9:49 am
by Webmaster
... in Row_Rendered Server Event.
For example:
if (CurrentPageID() == "add")
$this-><Field>->EditValue = <New Code>;
Re: Auto-generated string structure
Posted: Wed Aug 02, 2017 12:38 am
by Laim71
THANKS
IT works now.
I put the code generating function in global Code then called the function from Default value tag of the field.
Best Regards