This topic is locked

Concat values to be saved in DB

3/5/2022 6:13:49 PM
PHPRunner Tips and Tricks
I
Imran Minhas author

Hi, I have gone through lot of places but could not find the solution.

In my add page i have a field with lookup table where user will choose data from another table but in "Display field" i have custom expression "concat(quarter,' ',YEAR(CURDATE()))",, quater is the field value from another table.
now the data is displayed properly in list view page but in DB its only the quater data is saved. I want to save quater data and year also as it will populate later to many other tables and completer value quater+year is requird.

I have tried many things but failed. Please looking for urgent response. my verison is Phprunner 10.3

img alt

Thanks in Adance

D
david22585 3/7/2022

The display is only for the display of a field, not what is written to the DB. If you want to write it to the DB, you should use an event. When you do this though, it will have an issue if you have to go back and select a new quarter, as it won't have "Q4 2022" as a selectable option.

There are two ways to do this, in the quarter table, insert each selectable option do that it matches if you need to go back and edit data. For example, insert each quarter and year that you want as a selection. If you want to prevent other years, you can add an additional column that has the year, and in the WHERE clause, exclude years such as years that have past. This way the data matches as being selectable to what is selected and stored.

The second way is to make it as an before add event as follows:

$values["quarter"] = "".$values["quarter"]." ".year(curdate())."";

Sergey Kornilov admin 3/8/2022

What @david22585 suggests will work, except you need to use BeforeAdd event.

D
david22585 3/8/2022

What @admin said is correct. That was my mistake, and I corrected my post. It should be in the Before Add Event.