Artem Brat

Checking conditions with SQL queries when editing. SugarCRM 6.5

Discussion created by Artem Brat on Jul 20, 2017
Latest reply on Jul 21, 2017 by André Lopes

Hi guys.

SugarCRM 6.5

I created new custom module.

When editing, I check that certain conditions are met.

For example:

1. After selecting PARENT_TYPE, a SQL query was executed. Depending on the result of the SQL-query, some checkboxes were put, the message was displayed to the user.

2. When selecting the checkbox, a SQL query was executed. Depending on the result, the contents of the combo box changed.

3. If you selected the combo box, the SQL query was executed. Depending on the result of the SQL query, messages were displayed to the user.

I implemented some of the issues with editviewdefs.php and edit.js

--editviewdefs.php

$module_name = 'phone';
$viewdefs[$module_name]['EditView'] = array(
    'templateMeta' => array('maxColumns' => '2',
                                               'form' => array ('buttons' => array (0 => 'SAVE', 1 => 'CANCEL', ),),
                                               'includes'=> array(array('file'=>'modules/phone/js/phone.js'),          ),
                                               'javascript' => '<script>$(onchangeAddl)</script>',
                                               'widths' => array( array('label' => '10', 'field' => '30'), array('label' => '10', 'field' => '30')),),
'panels' =>array ('default' => array (array ('number','main_bool',),),),);

--phone.js

function onchangeAddl() {
$('#add_number_bool').attr('onchange', 'onchangeaddnpb(this)').change();
////When affixing MAIN
$('#main_bool').attr('onchange', 'onchangemain(this)').change();
////When selecting TYPE
$('#type_phone').attr('onchange', 'onchangetype(this)').change();
}
// when choosing MAIN
function onchangemain(elem) {
if ($('#type_phone').val()=='fax_type')
{
$('#main_bool').prop('checked', false);
alert("Message to the user");
}
}

//
function onchangetype(elem) {
if ($('#main_bool').prop('checked'))
{
if ($('#type_phone').val()=='fax')
{
$('#type_phone').val('work');
alert("Message to the user");
}
}
}
function onchangeaddnpb(elem) {
var checked = $(elem).is(':checked');
var table = $(elem).closest('table');
$('#addl_number', table).parent('td').add('#add_number_bool', table).toggle(checked);
}

 

How and where do I use SQL queries? 

I know that they can not be used in javascript.

 

Logic hooks after_save and before_save does not fit. 

How to stop saving in logic_hooks before_save 

I do not know how to interrupt saving. So I decided to check the "Save" button before clicking.

 

Thanks.

Artem Brat.

Outcomes