Setting Global Tags To User (for n-level multi-tenancy)
There are some predefined global tags (values) which you can use in every API called from the UI. You can also specify custom global tags (values) and use them in every API called from the UI.
I. Following are predefined global tags
A) User Id
JSScript:
session.getUser().getId()DB Action: Specify the parameter name in Input > User Id Parameter Name
DB Action (Manual SQL):
select:_userid from <Table name>
B) Username
JSScript:
session.getUser().getUsername()DB Action: Specify the parameter name in Input > Username Parameter Name
DB Action (Manual SQL):
select:_username from <Table name>
C) Tenant Id
JSScript:
session.getUser().getTenantIdentifier();DB Action: Specify the parameter name in Input > Tenant Id Parameter Name
DB Action (Manual SQL):
select:_tenantid from <Table name>
D) User Role
JSScript:
session.getUser().getRole()DB Action: Specify the parameter name in Input > Role Parameter Name
DB Action (Manual SQL):
select:_role from <Table name>
E) User's Browser Locale
JSScript:
context._userLanguageDB Action:
_userLanguage(only if DB action is API called from UI)
F) User's Time Zone Offset (in minutes)
JSScript:
context._timezoneOffsetDB Action:
_timezoneOffset(only if DB action is API called from UI)
II. You can add additional custom global tags as follows
If you want to get organizationId of the logged-in user and set it as a global tag (usable from any JavaScript or DB Action):
Select your Authentication Service mapped to your Web Application.
In the Post Authentication Script property, define the tags as follows:
user.userDetails = utils.createMap(); user.userDetails.organizationid = user.organizationid; // organizationid is a DB field in user table representing id of organization for logged in user.if (!utils.isNullOrEmpty(user.organizationid)) { // This method sends organizationid to EVERY server request from the UI utils.setValueAtPath(user, "userDetails.globalTags.organizationid", user.organizationid); }Click SAVE.
III. You can use additional custom global tags as follows
In JSScript actions:
context.<GLOBAL_TAG_NAME>(for example,context.organizationid)In DB Actions (SQL):
select:organizationid from <Table name>(based on our example above)