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
Reply
  • 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
Children