AnsweredAssumed Answered

Readonly fields based on related record

Question asked by Derick van Niekerk on Dec 12, 2016
Latest reply on Dec 13, 2016 by Derick van Niekerk

I need to check the related account on our custom billing module and make a field readonly based on if it's the primary billing record or not:

(From custom/Extension/modules/cost_Cost_Centre/Ext/Dependencies/billing_readonly_conditions.php )

 

$dependencies['cost_Cost_Centre']['readonly_dep'] = array(
    'hooks' => array("edit"),
    // 'trigger' => 'true' //<--- This works
    // this doesn't:
    'trigger' => 'equal(related($accounts_cost_cost_centre_1, "primary_account"), true)',
   
    'onload' => true,
    //Actions is a list of actions to fire when the trigger is true
    'actions' => array(
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'email1',
                'value' => 'true',
                ),
            ),
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'statement_preference_c',
                'value' => 'true',
                ),
            ),
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'bil_addr_formatted_address',
                'value' => 'true',
                ),
            ),
    ),
); 

I found the relationship name as suggested by the documentation:

Follow the steps listed below to find the name of the link fields for relationships that do not follow the convention above:

  1. Open the vardef file for the module you are working on: ./cache/modules/{module}/{module}vardefs.php
  2. Find the link field that matches the relationship you are looking for.

Which led me to the following:

 

 $GLOBALS["dictionary"]["cost_Cost_Centre"]=array (
  'table' => 'cost_cost_centre',
  'audited' => true,
  'activity_enabled' => false,
  'duplicate_merge' => true,
  'fields' =>
  array (
    // --- removed unrelated ---

    'accounts_cost_cost_centre_1' =>

    array (
      'name' => 'accounts_cost_cost_centre_1',
      'type' => 'link',
      'relationship' => 'accounts_cost_cost_centre_1',
      'source' => 'non-db',
      'module' => 'Accounts',
      'bean_name' => 'Account',
      'side' => 'right',
      'vname' => 'LBL_ACCOUNTS_COST_COST_CENTRE_1_FROM_COST_COST_CENTRE_TITLE',
      'id_name' => 'accounts_cost_cost_centre_1accounts_ida',
      'link-type' => 'one',
      'rel_fields' =>
      array (
        'primary_account' =>
        array (
          'type' => 'bool',
        ),
        'accounts_cost_cost_centre_1accounts_ida' =>
        array (
          'type' => 'id',
        ),
      ),
    ),
);

 

For some reason, my trigger always evaluates to false. I know the logic is triggering because if I set 'trigger' => 'true' it does make the fields readonly.

 

What am I missing? Am I using the wrong link name? I get no errors that I can find and I'm not sure how to debug Sugarlogic.

 

Help.

Outcomes