All Products
Search
Document Center

Identity as a Service:Account field expressions

Last Updated:Mar 31, 2026

IDaaS has a built-in expression engine that lets you transform user attributes before passing them to applications or identity providers. Use expressions in SAML and OpenID Connect (OIDC) applications to add or modify parameters in the returned user information—for example, to concatenate fields, evaluate conditions, or reformat values. You can also use expressions when configuring field mappings for identity provider (IdP) synchronization.

For more information, see SAML attribute statement mapping rules, OIDC id_token extension value mapping rules, and Manage account fields.

An expression consists of two parts:

  • Models — data sources, including User (IDaaS accounts) and AppUser (application accounts)

  • Functions — operations applied to model field values

Models

User

The User model represents IDaaS accounts. Reference fields using user.<fieldId>, for example user.username or user.lockExpireTime.

Field display nameField IDData typeRequiredUniqueUser permissionsDescription
Account IDuserIdStringNoYesVisibleThe user ID.
UsernameusernameStringYesYesVisibleThe username.
Display namedisplayNameStringNoNoEditableThe user's display name.
EmailemailStringNoYesEditableThe email address.
Mobile phonephoneNumberNumberNoYesEditableThe phone number.
Phone area codephoneRegionNumberNoNoEditableThe area code. For China, the value is 86 (without 00 or +).
External IDuserExternalIdStringNoYesVisibleThe user's external ID.
Source typeuserSourceTypeStringNoNoVisibleValid values: build_in (self-built), ding_talk (DingTalk), ad (AD), ldap (LDAP), we_com (WeCom), lark (Lark), idp_auto_build (automatically created by an IdP).
Source IDuserSourceIdStringNoNoVisibleThe source ID.
Account statusstatusStringNoNoVisibleValid values: enabled, disabled.
DescriptiondescriptionStringNoNoVisibleThe description.
Account expiration timeaccountExpireTimeNumberNoNoVisibleUNIX timestamp in milliseconds.
Account registration timeregisterTimeNumberNoNoVisibleUNIX timestamp in milliseconds.
Password expiration timepasswordExpireTimeNumberNoNoVisibleUNIX timestamp in milliseconds.
Lock expiration timelockExpireTimeNumberNoNoVisibleUNIX timestamp in milliseconds.
Creation timecreateTimeNumberNoNoVisibleUNIX timestamp in milliseconds.
Update timeupdateTimeNumberNoNoVisibleUNIX timestamp in milliseconds.

User model JSON example

{
  "userId": "user_x3zyd6cxxxxxxxxxxxxx",
  "username": "name_001",
  "displayName": "displayname_001",
  "passwordSet": true,
  "phoneRegion": "86",
  "phoneNumber": "333xxxx3333",
  "phoneNumberVerified": true,
  "email": "xxxxx@example.com",
  "emailVerified": true,
  "userExternalId": "b2ed5fc0xxxxxxxxxx",
  "userSourceType": "ding_talk",
  "userSourceId": "corp_1234xxxxxxx",
  "status": "enabled",
  "accountExpireTime": "-1",
  "passwordExpireTime": "-1",
  "registerTime": "1730454581598",
  "lockExpireTime": "-1",
  "createTime": "1730454582379",
  "updateTime": "1733479455307",
  "customFieldMap": {
    "place": { "fieldName": "place", "fieldValue": "beijing" },
    "age": { "fieldName": "age", "fieldValue": "18" }
  },
  "customFields": [
    { "fieldName": "place", "fieldValue": "beijing" },
    { "fieldName": "age", "fieldValue": "18" }
  ],
  "identityProviderUserMap": {
    "idp_m2gngriuenktdkxxxxxx": {
      "identityProviderId": "idp_m2gngriuenktdkxxxxxx",
      "identityProviderType": "ding_talk",
      "identityProviderExternalId": "corp_1234xxxxxxx",
      "identityProviderUserId": "b2ed5fc0xxxxx"
    }
  },
  "organizationalUnits": [
    { "organizationalUnitId": "ou_sdfadtaaxxxxxx", "organizationalUnitName": "name_001", "primary": false },
    { "organizationalUnitId": "ou_werttxxxxxx", "organizationalUnitName": "name_002", "primary": true }
  ],
  "primaryOrganizationalUnitId": "ou_werttxxxxxx",
  "groups": [
    { "groupId": "group_jp6al4sn4n4wjgjxxxxxx", "groupName": "group1", "groupExternalId": "group_jp6al4sn4n4wjgjxxxxxx" },
    { "groupId": "group_vavikcxewkf5h3oxxxxxx", "groupName": "group2", "groupExternalId": "group_vavikcxewkf5h3oxxxxxx" }
  ]
}

AppUser

The AppUser model represents application accounts. Reference fields using appUser.<property>, for example appUser.username.

PropertyDescription
usernameThe username of the application account.

IdP User

The IdP User model is used for field mappings when synchronizing with an identity provider. For example, the DingTalk office location field is idpUser.work_place. For available fields, see the documentation for your identity provider, such as the DingTalk Help Document - User Details.

Important

For OIDC identity providers (see Attach an OIDC identity provider), when using expressions in the automatic attachment feature, the idpUser. prefix applies only to the sub, phoneNumber, and email fields from the id_token (for example, idpUser.sub). For all other fields, use the idpUser.rawUserInfo. prefix (for example, idpUser.rawUserInfo.aud).

Functions

Functions operate on model field values and are grouped by category below.

String functions

FunctionSignatureReturn typeDescriptionExample
AppendAppend(str1, str2, ..., strN)StringConcatenates parameters into a new string. Equivalent to str1 + str2 + ....Append("str1", "@example.com")str1@example.com
JoinJoin(source1, source2, ..., sourceN, separator)StringJoins multiple source values into a single string using the specified separator.Join("str1", "str2", 123, "-")str1-str2-123
StringReplaceStringReplace(source, target, replacement)StringPerforms a simple string replacement of target in source with replacement.StringReplace("hello $str", "$str", "world")hello world
TrimTrim(source)StringRemoves leading and trailing whitespace.Trim(" 123 ")123
TrimLeftTrimLeft(source)StringRemoves leading whitespace only.TrimLeft(" 123 ")123
TrimRightTrimRight(source)StringRemoves trailing whitespace only.TrimRight(" 123 ") 123
ToLowerToLower(source)StringConverts to all lowercase.ToLower(" Abc ")abc
ToUpperToUpper(source)StringConverts to all uppercase.ToUpper(" Abc ")ABC
SubstringSubstring(source, fromIndex, endIndex)String | nullReturns the substring from fromIndex (inclusive) to endIndex (exclusive). If fromIndex is negative, it is treated as 0. Returns null if either index is not an integer.Substring("0123456", 1, 5)1234; Substring("0123456", -1, 7)0123456; Substring("0123456", "1", 5) → null
SubstringBeforeSubstringBefore(source, subString)String | nullReturns the portion of source before the first occurrence of subString. Returns null if subString is not found.SubstringBefore("test@example@com", "@")test
SplitSplit(source, separator)ArraySplits a string into an array of substrings using the specified separator.Split("str1,str2,str3", ",")Array(str1, str2, str3)
ContainsContains(str1, str2)BooleanReturns true if str1 contains str2, false otherwise.Contains("test", "t")true; Contains("test", "a")false
StartsWithStartsWith(str1, str2)BooleanReturns true if str1 starts with str2. Takes exactly two parameters.StartsWith("test", "t")true; StartsWith("test", "e")false
EqualsEquals(str1, str2[, ignoreCase])BooleanCompares two strings for equality. Pass true as the third parameter for case-insensitive comparison, or false for case-sensitive (the default).Equals("test", "Test")false; Equals("test", "Test", true)true

Condition functions

FunctionSignatureReturn typeDescriptionExample
IIFIIF(condition, whenTrue, whenFalse)AnyReturns whenTrue if condition is true, otherwise returns whenFalse.IIF(true, 1, 2)1; IIF(false, 1, 2)2
IsNullIsNull(value)BooleanReturns true if value is null or missing. Returns false for empty strings.IsNull(null)true; IsNull("")false
IsNullOrEmptyIsNullOrEmpty(value)BooleanReturns true if value is null or an empty string.IsNullOrEmpty(user.email)true if email is null or missing; IsNullOrEmpty("")true
CoalesceCoalesce(source1, source2, ..., sourceN, defaultValue)Any | nullReturns the first non-empty parameter. A non-empty value is not null and has a length greater than 0. Returns null if all parameters are empty.Coalesce("", user.phoneRegion, "86")86 if the phone area code is empty or missing
OrOr(condition1, condition2, ..., conditionN)BooleanReturns true if any condition is true.Or(true, false)true; Or(false, false)false
AndAnd(condition1, condition2, ..., conditionN)BooleanReturns true only if all conditions are true.And(true, false)false; And(true, true, true)true
xOrxOr(condition1, condition2)BooleanTakes exactly two conditions. Returns true if exactly one condition is true, false if both are the same.xOr(true, false)true; xOr(true, true)false; xOr(false, false)false

Array functions

FunctionSignatureReturn typeDescriptionExample
ArrayArray(source1, source2, ...)ArrayCombines values into an array. Values can be of the Object type.Array(1, 2, 3)[1, 2, 3]
ArrayAddArrayAdd(array, element)ArrayAdds an element to an array.ArrayAdd(Array(), "test")["test"]
ArrayMapArrayMap($ArrayObject, __item.ObjectProperty)ArrayCreates a new array by extracting a specific property from each object in an array.ArrayMap(user.groups, __item.groupId)["groupId1","groupId2","groupId3"]
ArrayIndexArrayIndex(array, n)AnyReturns the element at index n. Index starts from 0.ArrayIndex(Array(1, 2, 3), 0)1
ArrayJoinArrayJoin(array, separator)StringJoins array elements into a string using the specified separator.ArrayJoin(Array(1, 2, 3), "-")1-2-3

Object functions

FunctionSignatureReturn typeDescriptionExample
ObjectObject(key1, value1, key2, value2, ...)ObjectCreates an object from key-value pairs. Supports zero or an even number of parameters.Object("key1", "value1", "key2", "value2"){"key1": "value1", "key2": "value2"}
ObjectIndexObjectIndex(object, "propertyName")AnyReturns the value of the specified property. ObjectIndex(user, "username") is equivalent to user.username.
ObjectToJsonStringObjectToJsonString(object)StringConverts an object to a JSON string.ObjectToJsonString(user.groups) → JSON string representation

Time functions

FunctionSignatureReturn typeDescriptionExample
NowNow()StringReturns the current UTC date and time in yyyy-MM-dd'T'HH:mm:ssXXX format.Output: 2021-11-01T09:52:11Z
CurrentTimeMillisCurrentTimeMillis()NumberReturns the current UNIX timestamp in milliseconds.

Phone number functions

Both ExtractPhoneRegion and ExtractPhoneNumber use ISO 3166 Alpha-2 country codes (for example, CN, US, TW). See the ISO 3166 Country Codes standard for the full list.

The parameters work as follows depending on the format of the source phone number:

  • Number already has a `+` prefix (for example, +86131xxxxx000): pass only source. The function extracts the area code from the prefix.

  • Number has an area code but no `+` prefix (for example, 86131xxxxx000): pass source, defaultRegion, and set autoAppendPlusSignal to true.

  • Number has no area code (for example, 131xxxxx000): pass source, defaultRegion, and set autoAppendPlusSignal to false.

FunctionSignatureReturn typeDescription
ExtractPhoneRegionExtractPhoneRegion(source[, defaultRegion, autoAppendPlusSignal])StringExtracts the area code from a phone number.
ExtractPhoneNumberExtractPhoneNumber(source[, defaultRegion, autoAppendPlusSignal])StringExtracts the phone number without the area code.

ExtractPhoneRegion examples

Phone number formatExpressionReturn value
+86131xxxxx000, +86 131xxxxx000, or +86-131xxxxx000ExtractPhoneRegion(idpUser.mobile)86
86131xxxxx000, 86 131xxxxx000, or 86-131xxxxx000ExtractPhoneRegion(idpUser.mobile, "CN", true)86
131xxxxx000ExtractPhoneRegion(idpUser.mobile, "CN", false)86

ExtractPhoneNumber examples

Phone number formatExpressionReturn value
+86131xxxxx000, +86 131xxxxx000, or +86-131xxxxx000ExtractPhoneNumber(idpUser.mobile)131xxxxx000
86131xxxxx000, 86 131xxxxx000, or 86-131xxxxx000ExtractPhoneNumber(idpUser.mobile, "CN", true)131xxxxx000
131xxxxx000ExtractPhoneNumber(idpUser.mobile, "CN", false)131xxxxx000

SAML-specific functions

FunctionSignatureReturn typeDescriptionExample
SamlArraySamlArray(Array())SAML attributeAvailable only for SAML SSO. Formats an array as a SAML attribute with multiple AttributeValue elements.SamlArray(Array("group1","group2")) → SAML response with separate <saml2:AttributeValue> elements for group1 and group2

Common expressions

The following examples use the sample user data below. Copy and adapt these expressions directly.

Sample user data:

  • user.username: name_001

  • user.displayName: displayname_001

  • user.email: xxxxx@example.com

  • user.phoneRegion: 86

  • user.phoneNumber: 333xxxx3333

  • user.groups: two groups with IDs group_jp6al4sn4n4wjgjxxxxxx and group_vavikcxewkf5h3oxxxxxx

GoalExpressionOutput
Append a domain to the usernameAppend(user.username, "@example.com")name_001@example.com
Return email if set, otherwise fall back to phone numberCoalesce(user.email, user.phoneNumber)xxxxx@example.com
Use a default phone number when the field is emptyIIF(IsNullOrEmpty(user.phoneNumber), "1888888****", user.phoneNumber)333xxxx3333
Concatenate the area code and phone number with a hyphenJoin(user.phoneRegion, user.phoneNumber, "-")86-333xxxx3333
Build a welcome message with the display nameStringReplace("hello $DisplayName", "$DisplayName", user.displayName)hello displayname_001
Mask the middle four digits of the phone numberAppend(SubString(user.phoneNumber, 0, 4), "****", SubString(user.phoneNumber, 8, 10))333x****33
Extract the username from an email addressSubstringBefore(user.email, "@")xxxxx
Format the email field as a SCIM-compatible arrayArray(Object("email", user.email, "type", "work", "primary", true))[{"email":"xxxxx@example.com","type":"work","primary":true}]
Get a list of group IDs for a userArrayMap(user.groups, __item.groupId)["group_jp6al4sn4n4wjgjxxxxxx","group_vavikcxewkf5h3oxxxxxx"]