LogoLogo
Enterprise GuideCommunity Edition GuideDeveloper Guide
  • Using The Polarity Developer Guide
  • Quick Start
    • What's New
    • Installing Integrations
    • Quick Start Guide
    • Learning Resources
  • Building an Integration
    • Directory Layout
    • package.json
    • Configuration File
    • Integration Main Module
      • startup
      • doLookup
        • Entity Objects
        • Result Objects
        • Error Objects
      • onDetails
      • onMessage
      • validateOptions
    • Customizing the Overlay Window
      • Templates
        • Conditionals
        • Displaying a List of Items
        • Display Object Properties
        • Built-in Helpers
        • Displaying Icons
      • Component File
        • Aliased Properties
        • Computed Properties
        • Event Hooks
      • CSS Styles
    • Vendor Javascript
      • Inserting Javascript into DOM
    • README Guide
    • Debugging Integrations
      • Web Inspector
      • Using Integration Logs
      • Testing Main Module
  • Recipes
    • Enabling User Actions
    • Throttling Lookups
    • Using Custom Entity Types
    • Custom Summary Tags
    • Creating a Tabbed Interface
    • Accessing Username of Requestor
Powered by GitBook
On this page
  • doLookup Example
  • onDetails Example
  • onMessage Example
  1. Recipes

Accessing Username of Requestor

You can access information about the requesting user from within the doLookup, onDetails, and onMessage hooks.

If you want to access the username or id of the requesting user from within the doLookup onDetails or onMessage method you can easily do this by accessing the _request property on the options variable passed into the respective method. The _request property contains a user object which includes a username and id property.

The structure of the _request property is as follows

// _request property on the `options` variable
{
    _request: {
        user: {
            username: 'admin', //username of the requesting user
            id: 5 // user if of the requesting user
        }
    }
}

The id property is a unique internal identifier used by Polarity to track the user. The id is a numeric value and does not change even if the user updates their username.

doLookup Example

Here is an example for how you would access the username and id of the requesting user from within the doLookup method.

integration.js
function doLookup(entities, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    
    // make use of `username` and/or `userId`
    ...

onDetails Example

integration.js
function onDetails(lookupResult, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    // use `username` and `userId` as required
    ...

onMessage Example

integration.js
function onMessage(payload, options, cb){
    let username = options._request.user.username;
    let userId = options._request.user.id;
    // use `username` and `userId` as required
    ...
PreviousCreating a Tabbed Interface

Last updated 5 years ago