Skip to main content

AML user attributes and variables

Introduction

AML expressions can use runtime context from the current user and the current Git environment. This is useful when the same AML code needs to behave differently for different users, teams, branches, or production environments.

You can use these values anywhere AML accepts an expression, such as dynamic data source names, dynamic schemas, or AI custom context.

User attributes

Use H.current_user.<attribute_name> to access any custom user attribute of the current user. For example, H.current_user.data_source returns the current user's data_source attribute, which you can use to route each user to the correct database.

Before referencing a custom user attribute in AML, define it in User Attributes Management. The attribute name in AML must match the user attribute name exactly.

Dataset sales {
data_source_name: H.current_user.data_source
models: [orders]
}

Use user attributes in conditional logic

User attributes also work well with if-else expressions. In this example, analysts and marketers receive different AI context based on their team attribute.

const ai_context = @md

${
if (H.current_user.team == 'Business Analyst') {
'Focus on product performance, margin, and inventory analysis.'
} else if (H.current_user.team == 'Growth & Marketing') {
'Focus on customer acquisition, retention, and campaign performance.'
} else {
'Answer using the standard company definitions in the semantic layer.'
}
}

;;

System user attributes

System user attributes are provided by Holistics, prefixed with h_, and cannot be modified by users.

AttributeDescription
H.current_user.h_emailThe email of the current user account.
H.current_user.h_roleThe role of the current user account, such as admin, analyst, explorer, or viewer.

In this example, admins connect to the production database while other roles are routed to a restricted data source:

Dataset sales {
data_source_name:
if (H.current_user.h_role == 'admin') {
'production_data_source'
} else {
'restricted_data_source'
}
models: [orders]
}

Holistics built-in variables

Holistics also provides built-in variables for the current Git and deployment context. These are useful when you want different behavior in development and production.

VariableDescription
H.git.current_branchReturns the name of the current Git branch.
H.git.is_productionReturns true when in the Reporting tab or in the Development workspace with production mode enabled.

For example, this setup uses each user's data_source attribute in production, but always uses a development database while modeling:

Dataset sales {
data_source_name:
if (H.git.is_production) {
H.current_user.data_source
} else {
'development_data_source'
}
models: [orders]
}

Common use cases

These variables are most commonly used when your AML project needs to adapt at runtime:


Open Markdown
Let us know what you think about this document :)