Page 1 of 1

Auto fill with a previous value

Posted: Fri Aug 18, 2017 8:36 pm
by raphi5430

Hi!
I have the following question.
Is it possiblie that when you add a new row that you can auto fill a field with the value of the field from the previous row you added?


Re: Auto fill with a previous value

Posted: Fri Aug 18, 2017 10:42 pm
by kirondedshem

1.create a function in global code to pick the latest value form whatever filed of whatever table. eg
GetLastestValue()
{
return ew_ExecuteScalar("SELECT field from table order by field_2 desc LIMIT 1");
}

  1. go to field settings of that field and in default Add->Default value paste the function as GetLastestValue(), not quotes, no termination

Re: Auto fill with a previous value

Posted: Mon Aug 21, 2017 2:53 pm
by raphi5430

Thanks, that worked for me!


Re: Auto fill with a previous value

Posted: Wed Oct 11, 2017 7:06 pm
by goldenaxe

kirondedshem wrote:
1.create a function in global code to pick the latest value form whatever filed of
whatever table. eg
GetLastestValue()
{
return ew_ExecuteScalar("SELECT field from table order by feild_2 desc LIMIT
1");
}

  1. go to field settings of that field and in default Add->Default value paste the
    function as GetLastestValue(), not quotes, no termination

Hello,
Thanks for your explain. I want to do the same thing. I'm a new user for phpmaker.
I can not do this . How can I create function in global code ? What is the mean of "global code "?

Thank you very much.


Re: Auto fill with a previous value

Posted: Wed Oct 11, 2017 10:22 pm
by mobhar

"Global Code" is a part of "Server Events" in your PHPMaker project. It is the place where your own code to be included in all PHP pages. This may contain your constants, variables, functions and classes.

For more info and example, please read "Server Events and Client Scripts" -> "Global -> All Pages" -> "Global Code" from PHPMaker Help menu.