If you want to change whether a field is required dynamically, look into Dependency Actions.
They allow you to automatically switch the required-state (true/false) of a given target field based on the value of a custom Sugar Logic formula.
Based on the linked example and your example it would look something like this:
./custom/Extension/modules/<module>/Ext/Dependencies/fieldB_required.php
<?php
$dependencies['<module>']['fieldB_required'] = array(
'hooks' => array("edit"),
//Trigger formula for the dependency. Defaults to 'true'.
'trigger' => 'true',
'triggerFields' => array('fieldA'),
'onload' => true,
//Actions is a list of actions to fire when the trigger is true
'actions' => array(
array(
'name' => 'SetRequired', //Action type
//The parameters passed in depend on the action type
'params' => array(
'target' => 'fieldB',
'label' => '<field label>', //normally <field>_label
'value' => 'equal($fieldA, 1)', //Formula
),
),
),
);
fieldA
is the field that, when changed, triggers a re-evaluation of the formula and will set the required state of target field fieldB
to the value of equal($fieldA, 1)
.
Notes:
- While the Dependency Action is defined in a PHP file, the formula you provide is usually executed on the client/javascript-side of things, therefore saving you the need to write custom javascript code.
- This is a SugarCRM feature but it's quite old, so SuiteCRM hopefully still supports it.