How to add status field on module based on some condition?

I have use case where when I click on 'Activate' button ,an API is trigerred which will show an alert boc saying "Account is activated". 

Now , I want to add one field like below screen which will refelct the status of accounts. <<Ignore module name and other information it's just for reference>>

Please help me with some suggestions or any code snippet.

Parents Reply Children
  • I managed to have it locally on the Accounts module with the following steps: 

    1 - Create the active_c field in Studio 

    2 - Add the field to the record view. 

    3 - Edit the file custom/modules/Accounts/clients/base/views/record/record.php to add the 'active' field to the panel_header. 

    This is the outcome: 

    I have attached my custom/modules/Accounts/clients/base/views/record/record.php here so you can have a look. 

    <?php
    $viewdefs['Accounts'] = 
    array (
      'base' => 
      array (
        'view' => 
        array (
          'record' => 
          array (
            'buttons' => 
            array (
              0 => 
              array (
                'type' => 'button',
                'name' => 'cancel_button',
                'label' => 'LBL_CANCEL_BUTTON_LABEL',
                'css_class' => 'btn-invisible btn-link',
                'showOn' => 'edit',
                'events' => 
                array (
                  'click' => 'button:cancel_button:click',
                ),
              ),
              1 => 
              array (
                'type' => 'rowaction',
                'event' => 'button:save_button:click',
                'name' => 'save_button',
                'label' => 'LBL_SAVE_BUTTON_LABEL',
                'css_class' => 'btn btn-primary',
                'showOn' => 'edit',
                'acl_action' => 'edit',
              ),
              2 => 
              array (
                'type' => 'actiondropdown',
                'name' => 'main_dropdown',
                'primary' => true,
                'showOn' => 'view',
                'buttons' => 
                array (
                  0 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:edit_button:click',
                    'name' => 'edit_button',
                    'label' => 'LBL_EDIT_BUTTON_LABEL',
                    'acl_action' => 'edit',
                  ),
                  1 => 
                  array (
                    'type' => 'shareaction',
                    'name' => 'share',
                    'label' => 'LBL_RECORD_SHARE_BUTTON',
                    'acl_action' => 'view',
                  ),
                  2 => 
                  array (
                    'type' => 'pdfaction',
                    'name' => 'download-pdf',
                    'label' => 'LBL_PDF_VIEW',
                    'action' => 'download',
                    'acl_action' => 'view',
                  ),
                  3 => 
                  array (
                    'type' => 'pdfaction',
                    'name' => 'email-pdf',
                    'label' => 'LBL_PDF_EMAIL',
                    'action' => 'email',
                    'acl_action' => 'view',
                  ),
                  4 => 
                  array (
                    'type' => 'divider',
                  ),
                  5 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:find_duplicates_button:click',
                    'name' => 'find_duplicates_button',
                    'label' => 'LBL_DUP_MERGE',
                    'acl_action' => 'edit',
                  ),
                  6 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:duplicate_button:click',
                    'name' => 'duplicate_button',
                    'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
                    'acl_module' => 'Accounts',
                    'acl_action' => 'create',
                  ),
                  7 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:historical_summary_button:click',
                    'name' => 'historical_summary_button',
                    'label' => 'LBL_HISTORICAL_SUMMARY',
                    'acl_action' => 'view',
                  ),
                  8 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:audit_button:click',
                    'name' => 'audit_button',
                    'label' => 'LNK_VIEW_CHANGE_LOG',
                    'acl_action' => 'view',
                  ),
                  9 => 
                  array (
                    'type' => 'divider',
                  ),
                  10 => 
                  array (
                    'type' => 'rowaction',
                    'event' => 'button:delete_button:click',
                    'name' => 'delete_button',
                    'label' => 'LBL_DELETE_BUTTON_LABEL',
                    'acl_action' => 'delete',
                  ),
                ),
              ),
              3 => 
              array (
                'name' => 'sidebar_toggle',
                'type' => 'sidebartoggle',
              ),
            ),
            'panels' => 
            array (
              0 => 
              array (
                'name' => 'panel_header',
                'label' => 'LBL_PANEL_HEADER',
                'header' => true,
                'fields' => 
                array (
                  0 => 
                  array (
                    'name' => 'picture',
                    'type' => 'avatar',
                    'size' => 'large',
                    'dismiss_label' => true,
                    'readonly' => true,
                  ),
                  1 => 
                  array (
                    'name' => 'name',
                  ),
                  2 => 
                  array (
                    'name' => 'favorite',
                    'label' => 'LBL_FAVORITE',
                    'type' => 'favorite',
                    'dismiss_label' => true,
                  ),
                  3 => 
                  array (
                    'name' => 'follow',
                    'label' => 'LBL_FOLLOW',
                    'type' => 'follow',
                    'readonly' => true,
                    'dismiss_label' => true,
                  ),
                  4 => 
                  array (
                    'readonly' => false,
                    'name' => 'active_c',
                    'label' => 'LBL_ACTIVE',
                  ),
                ),
              ),
              1 => 
              array (
                'name' => 'panel_body',
                'label' => 'LBL_RECORD_BODY',
                'columns' => 2,
                'placeholders' => true,
                'newTab' => false,
                'panelDefault' => 'expanded',
                'fields' => 
                array (
                  0 => 
                  array (
                    'readonly' => false,
                    'name' => 'active_c',
                    'label' => 'LBL_ACTIVE',
                  ),
                  1 => 
                  array (
                  ),
                  2 => 'website',
                  3 => 'industry',
                  4 => 'parent_name',
                  5 => 'account_type',
                  6 => 'business_center_name',
                  7 => 'service_level',
                  8 => 'assigned_user_name',
                  9 => 'phone_office',
                  10 => 
                  array (
                    'name' => 'tag',
                    'span' => 12,
                  ),
                ),
              ),
              2 => 
              array (
                'name' => 'panel_hidden',
                'label' => 'LBL_RECORD_SHOWMORE',
                'hide' => true,
                'columns' => 2,
                'placeholders' => true,
                'newTab' => false,
                'panelDefault' => 'expanded',
                'fields' => 
                array (
                  0 => 
                  array (
                    'name' => 'billing_address',
                    'type' => 'fieldset',
                    'css_class' => 'address',
                    'label' => 'LBL_BILLING_ADDRESS',
                    'fields' => 
                    array (
                      0 => 
                      array (
                        'name' => 'billing_address_street',
                        'css_class' => 'address_street',
                        'placeholder' => 'LBL_BILLING_ADDRESS_STREET',
                      ),
                      1 => 
                      array (
                        'name' => 'billing_address_city',
                        'css_class' => 'address_city',
                        'placeholder' => 'LBL_BILLING_ADDRESS_CITY',
                      ),
                      2 => 
                      array (
                        'name' => 'billing_address_state',
                        'css_class' => 'address_state',
                        'placeholder' => 'LBL_BILLING_ADDRESS_STATE',
                      ),
                      3 => 
                      array (
                        'name' => 'billing_address_postalcode',
                        'css_class' => 'address_zip',
                        'placeholder' => 'LBL_BILLING_ADDRESS_POSTALCODE',
                      ),
                      4 => 
                      array (
                        'name' => 'billing_address_country',
                        'css_class' => 'address_country',
                        'placeholder' => 'LBL_BILLING_ADDRESS_COUNTRY',
                      ),
                    ),
                  ),
                  1 => 
                  array (
                    'name' => 'shipping_address',
                    'type' => 'fieldset',
                    'css_class' => 'address',
                    'label' => 'LBL_SHIPPING_ADDRESS',
                    'fields' => 
                    array (
                      0 => 
                      array (
                        'name' => 'shipping_address_street',
                        'css_class' => 'address_street',
                        'placeholder' => 'LBL_SHIPPING_ADDRESS_STREET',
                      ),
                      1 => 
                      array (
                        'name' => 'shipping_address_city',
                        'css_class' => 'address_city',
                        'placeholder' => 'LBL_SHIPPING_ADDRESS_CITY',
                      ),
                      2 => 
                      array (
                        'name' => 'shipping_address_state',
                        'css_class' => 'address_state',
                        'placeholder' => 'LBL_SHIPPING_ADDRESS_STATE',
                      ),
                      3 => 
                      array (
                        'name' => 'shipping_address_postalcode',
                        'css_class' => 'address_zip',
                        'placeholder' => 'LBL_SHIPPING_ADDRESS_POSTALCODE',
                      ),
                      4 => 
                      array (
                        'name' => 'shipping_address_country',
                        'css_class' => 'address_country',
                        'placeholder' => 'LBL_SHIPPING_ADDRESS_COUNTRY',
                      ),
                      5 => 
                      array (
                        'name' => 'copy',
                        'label' => 'NTC_COPY_BILLING_ADDRESS',
                        'type' => 'copy',
                        'mapping' => 
                        array (
                          'billing_address_street' => 'shipping_address_street',
                          'billing_address_city' => 'shipping_address_city',
                          'billing_address_state' => 'shipping_address_state',
                          'billing_address_postalcode' => 'shipping_address_postalcode',
                          'billing_address_country' => 'shipping_address_country',
                        ),
                      ),
                    ),
                  ),
                  2 => 
                  array (
                    'name' => 'phone_alternate',
                    'label' => 'LBL_PHONE_ALT',
                  ),
                  3 => 'email',
                  4 => 'phone_fax',
                  5 => 'campaign_name',
                  6 => 
                  array (
                    'name' => 'twitter',
                  ),
                  7 => 
                  array (
                  ),
                  8 => 
                  array (
                    'name' => 'description',
                    'span' => 12,
                  ),
                  9 => 'sic_code',
                  10 => 'ticker_symbol',
                  11 => 'annual_revenue',
                  12 => 'employees',
                  13 => 'ownership',
                  14 => 'rating',
                  15 => 
                  array (
                    'name' => 'duns_num',
                    'readonly' => true,
                  ),
                  16 => 
                  array (
                    'name' => 'date_entered_by',
                    'readonly' => true,
                    'inline' => true,
                    'type' => 'fieldset',
                    'label' => 'LBL_DATE_ENTERED',
                    'fields' => 
                    array (
                      0 => 
                      array (
                        'name' => 'date_entered',
                      ),
                      1 => 
                      array (
                        'type' => 'label',
                        'default_value' => 'LBL_BY',
                      ),
                      2 => 
                      array (
                        'name' => 'created_by_name',
                      ),
                    ),
                  ),
                  17 => 'team_name',
                  18 => 
                  array (
                    'name' => 'date_modified_by',
                    'readonly' => true,
                    'inline' => true,
                    'type' => 'fieldset',
                    'label' => 'LBL_DATE_MODIFIED',
                    'fields' => 
                    array (
                      0 => 
                      array (
                        'name' => 'date_modified',
                      ),
                      1 => 
                      array (
                        'type' => 'label',
                        'default_value' => 'LBL_BY',
                      ),
                      2 => 
                      array (
                        'name' => 'modified_by_name',
                      ),
                    ),
                  ),
                ),
              ),
            ),
            'templateMeta' => 
            array (
              'useTabs' => false,
            ),
          ),
        ),
      ),
    );
    


    Mind that if the field is empty it will not show, as it does not show the label if it is not in Edit mode. 

    I hope this helps

  • Thanks . the field was empty that's why it was not visible . My Bad. Appreciated your time and suggestion.

    But there is one challenge here ... once I reload the page or navigate somewhere else and coming back to same record again , status is not saved.(Changes are not saved). 

    I dn't want to click on 'Save' button after status gets updated to save the changes as I have some different logic written on OnSave logic hooks. If I do that logic written in onsave logic hook will also get executed. 

    Anyway to overcome this challenge.