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.

  • Hello

    To add fields there you should be looking at the panel_header inside record.php file: 


    custom/modules/<modulename>/clients/base/views/record/record.php


    I hope this helps. 

    André

  • Hi  I have added below line of code in custom/modules/<modulename>/clients/base/views/record/record.php

    Bt it is not visible on screen. Also created en_us.status.php file in custome/Extensions/modules/<<modulename>>/Ext/Language. 

    Please suggest if any thing is missing. 

    record.php

    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' => 'activate',
    'label' => 'LBL_ACTIVATE',
    'type' => 'follow',
    'readonly' => true,
    'dismiss_label' => true,
    ),
    ),
    ),

  • Hi

    Was the 'activate' field created in Studio? 

    You could try adding it to the record view via studio before to make sure you got the naming correctly. 

    After that,perform the changes in the file :

    custom/modules/<modulename>/clients/base/views/record/record.php

    Let me know if this helps

  • HiThe dropdown field ('activate') is created in studio. even after that the field is not visible on screen.

    record.php

    4 =>
    array (
    'name' => 'customerstatus_c',
    'label' => 'LBL_CUSTOMERSTATUS',
    'readonly' => true,
    ),

  • 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

  • Hi Gautam,

    If you want something like below screenshot,

    Screenshot

    These are the steps you need to follow,

    1. Create a checkbox field named activated_c through studio.
    2. Make the field calculated and give formula as below,
      ifElse(equal($customerstatus_c,"Activated"), 1 , 0).
    3. The above formula will evaluate to 1 if customer status is Activated else 0.
    4. Download this file and extract it in custom/modules/<modulename>/clients/base/views/fields/.
    5. Now simply in record.php just add this few lines of code in fields array of panel header at last index.
      array(
                  'name' => 'panel_header',
                  'header' => true,
                  'fields' => array(
                      array(
                          'name' => 'picture',
                          'type' => 'avatar',
                          'size' => 'large',
                          'dismiss_label' => true,
                      ),
                      array(
                          'name' => 'name',
                          'type' => 'fullname',
                          'label' => 'LBL_NAME',
                          'dismiss_label' => true,
                      ),
                      array(
                          'type' => 'favorite',
                      ),
                      array(
                          'type' => 'follow',
                          'readonly' => true,
                      ),
                      array(
                          'name' => 'activated_c',
                          'type' => 'badge',
                          'dismiss_label' => true,
                          'readonly' => true,
                      ),
                  ),
              ),
    6. Now you will be able to see Activated label at top if the status is Activated else if the status if Other than Activated it will be shown as Not Activated.

    Hope this may help you.

    Vamshi S.

  • Thank you This is exactly what i was looking for. Appreciated your help.

    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. 

    Please suggest  some way how we can overcome this problem.

  • 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.

  • Hi , the formula is invalid .It says "The formula must be of type boolean". Please suggest the changes

  • To save the changes updated in Javascript Controller you can use,

    this.model.save()

    Adding this line of code will save all the changes in the record view. 

    But this.model.save() will also call onSave logic hook. If you don't want the code in logic hook to be executed, you can do something like below.

    1. Create a custom field (Checkbox).
    2. Add a condition in onSave logic hook such that the code will execute if only the custom field is checked.
    3. Now where ever you save the record make this custom field as true if you want the logic hook to be executed otherwise false.