AnsweredAssumed Answered

Sugarlogic related field causes infinite loop

Question asked by Derick van Niekerk on Apr 10, 2017
Latest reply on Apr 11, 2017 by Derick van Niekerk

I want to make some fields readonly based on the value in a related field. I have created this in 'custom/<module>/Ext/Dependencies/dependency_hide_field_for_primary_br.php'

 

$dependencies['cost_Cost_Centre']['readonly_fields'] = array(
    'hooks' => array("edit"),
    //Optional, the trigger for the dependency. Defaults to 'true'.
    'trigger' => 'equal(related($accounts_cost_cost_centre_1, "primary_account"), "1")',
    'onload' => 'true',
    //Actions is a list of actions to fire when the trigger is true
    'actions' => array(
        array(
            'name' => 'ReadOnly',
            //The parameters passed in will depend on the action type set in 'name'
            'params' => array(
                'target' => 'company_trading_as_c',
                'value' => 'true',
            ),
        ),
        array(
            'name' => 'ReadOnly',
            //The parameters passed in will depend on the action type set in 'name'
            'params' => array(
                'target' => 'legal_entity_name_c',
                'value' => 'true',
            ),
        ),
    ),
); 

 

The fields are made readonly if I remove the trigger condition. If I have the trigger condition as above, my network log shows the account relationship being reloaded over and over again:

 

The same URL being requested repeatedly (related account)

 

The response for these requests are always the same on each of these requests:

{"id":"d0e481a4-d9a8-3817-33e9-58449c471bc4","date_modified":"2017-04-10T14:25:26+12:00","_acl":{"fields":{}},"_module":"Accounts"}

 

It looks like each load of the related record triggers another load. The 'primary_account' field is inside the relationship table, and not in the Accounts module - could this be the cause of the issue?

 

How do I set the dependency to make the fields readonly based on the 'primary_account' field in the relationship?

Outcomes