Avoid new records creation in subpanels, based on Father module detail view field information

Hi and thanks!!!

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.

is this possible? any suggest?

thanks!!

Maybe this will help you get closer to a solution:

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/22188-customize-the-top-subpanel-create-button

I am thinking that if you can customize the create button in the subpanel, maybe you can add some code to it, to test your conditions…

But I don’t know exactly how to do it, you will have to experiment…

I will check your idea , but i think i have it

logic hook before saving, i make query to know if in the relationship table i have more than 2 using the id_c

i let you know if i achive it

Thanks

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…

Thanks for your help!!

i almost achived

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’);

  $urlParameters = array( 
    'module' => "bitag_BitacoraAgronomica", 
    'action' => "EditView",
    'record' => $tel_id, 
    'parent_module' =>$parent_module_url,
    'parent_id'=>$hol_parent_id,
    'return_module'=>$parent_module_url,
    'return_id'=>$hol_parent_id,
  );
  $url = 'index.php?' . http_build_query($urlParameters); 

  SugarApplication::redirect($url); 
}

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

im thinking about the solution

REGARDSSSS!!