AnsweredAssumed Answered

Custom dependencies and conditional readonly fields

Question asked by Andrew Gin on Feb 16, 2017
Latest reply on Mar 26, 2018 by r. adrian aguilera perez

Hi

I want to make all fields/the entire Opportunity record readonly once the sales stage is "Closed Won" and the user is not an administrator.

Here is what I have so far in /custom/Extension/modules/Opportunities/Ext/Dependencies/opportunity_read_only.php:

<?php
global $current_user;
$dependencies['Opportunities']['lock_opportunity_dep'] = array(
    'hooks' => array("edit"),
    'trigger' => 'and(equal($sales_stage, "Closed Won"),equal($current_user->is_admin, true))',
    //'triggerFields' => array('sales_stage'),
    'onload' => true,
    'actions' => array(
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'description',
                'value' => 'true',
            ),
        ),
        //.. all other fields here...
        array(
            'name' => 'ReadOnly',
            'params' => array(
                'target' => 'name',
                'value' => 'true',
            ),
        ),
    ),
);

The above does not work; when I remove the admin check, the fields are locked correctly, so it appears $current_user cannot be used as part of the trigger because it is not a field in the Opportunity module.

  1. How do I check whether the current user is an admin and use it as part of the trigger?
  2. How can I loop through all fields in the module (in this case, Opportunities) instead of having to manually specify a ReadOnly array for each field?

Outcomes