What is the best way to add custom field attributes to app.user?

I have some custom fields on User, e.g support_group_c, that I use repeatedly to set defaults and determine which custom view to show on Cases etc.
I find myself repeatedly having to pull the full user bean to get the values for these fields.
Unfortunately app.user does not seem to include these custom fields.

What is the best route to have those values available throughout the app?
Should I be trying to override the GET /me ?

thanks,
FrancescaS
Parents
  • Hi Francesa and Jeff,

    I would like to extend on what Jeff wrote with some more details and a code example. This can be accomplished by following this Dev Guide article. Here is my extended API code:

    File: ./custom/clients/base/api/CustomCurrentUserApi.php
    require_once("clients/base/api/CurrentUserApi.php");    class CustomCurrentUserApi extends CurrentUserApi  {      public function registerApiRest()      {          //in case we want to add additional endpoints          return parent::registerApiRest();      }        // override the retrieveCurrentUser function      public function retrieveCurrentUser($api, $args)      {          global $current_user;            $current_user_results = parent::retrieveCurrentUser($api, $args);          $user_data = $current_user_results['current_user'];            // add custom fields here:          $user_data['custom_field_c'] = $current_user->custom_field_c;            return array('current_user' => $user_data);      }  }
    Then from within JavaScript you should be able to access your custom fields via:
    app.user.get("custom_field_c");
    -Mark
  • Hello,

    I have tried to get Full name of user using App.user.get

    console.log(App.user.get("full_name"));

    It giving me undefined in console.

    Any suggestion for this?

    One I get full name value then I can go for this solution for custom field.

  • full_name is retrieved by default so it should be available to you.

    Where are you in the application when you try to use it?

    I don't think there is a difference between App and app, I use app.user.get('<fieldname>') in the initialize in custom/modules/Cases/clients/base/views/record/record.js and it works for me.

    FrancescaS

Reply Children
No Data