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.

  • Hi Hiren,

    What is the error being received? App vs app can make a difference as JavaScript is a case sensitive language so these are seen as two separate objects.

    When testing code from the JavaScript console, you have to use the global "App". From inside your code it is generally recommended to use "app" instead as it should have context and scope from within the code.

    -Mark

Reply Children
No Data