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

  • 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.
Reply
  • 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.
Children
No Data