i have a problem. For some modules in my CRM i have to avoid the creation of new records (not able to create in the Quick create view) when “something” in a field of the father module.
example
i have a subpanel, “land analisys”, if the module father is a “impact area” then i want to let the user create only 1 “land analisys”
if the father module is a “extension area” i want to let the user to create 2 “land analisys”
ther is not a case when the user jave to create 3 “land analisys” , then iwant to avoid that posiblility.
If you use a logic hook, it’s easier, but you are limited, you can only work on the back end, not on the front end. You can block the edit from saving, with a very inelegant message to the user, but that’s it.
In order to do things properly you would have to get some code into the screen at the moment when it is constructed. And perhaps some extra Javascript to make things easier to use and clearer for the user to understand…
first, logic hook make a query to know how many relations between the modules have.
$vecesIDdeBitacora = $GLOBALS[‘db’]->getOne(“select count(bitag_parte2_bitag_bitacoraagronomica_1bitag_parte2_ida) from bitag_parte2_bitag_bitacoraagronomica_1_c where bitag_parte2_bitag_bitacoraagronomica_1bitag_parte2_ida = ‘$relate_id’”);
then, if the number is more than two i redirect to the same module where i am (or the user is)
if($vecesIDdeBitacora > 2) {
//throw new Exception(‘My error Message’);
the actual problem is the quick create, when i create a new ‘analisis de suelo’ it create the relation y the table bitag_parte2_bitag_bitacoraagronomica_1_c, thats the table i use to count, then it break my logic.
when i make a query to the bitag_bitacoraagronomica_cstm the new record DOES NOT EXIST!!!
the logic hook works well, but i dont know why in the bitag_parte2_bitag_bitacoraagronomica_1_c the relation is created. If go to one of the 2 analsis de suelo created before and i try to save the logic hook wont let me save becsause the query will be more than 2