How to trim whitespaces of an attribute
All Identity Manager
Policy Xpress to provide a trim function. Create a policy using PX -> Data -> General -> String Parser -> here you will see the trim function.
Here is an example of the PX Policy using the Trim function to trim leading and trailing whitespace on the UserID attribute for the Create user task:
Policy Name: Trim UserID - UI
Policy Type: UI
Event State: Submission
Event Name: Create User (CreateUser)
Data Element Name: get_UserID
Category: Attributes
Type: User Attribute
Function: Get
Attribute Name: User ID (%USER_ID%)
Data Element Name: trimmed_UserID
Category: General
Type: String Parser
Function: Trim
String: {'get_UserID'}
Scope: Both
Data Element Name: Trim_Needed
Category: Comparators
Type: Comparator
Function: Compare Strings
First String: {'get_UserID'}
Second String: {'trimmed_UserID'}
Entry Rule Name: CheckIfTrimNeeded
Data Element: Trim_Needed
Operator: Not equals
Value: EQUALS
Action Name: set_UserID
Category: Attributes
Type: Set User Values
Function: Set
Attribute Name: User ID (%USER_ID%)
Value: {'trimmed_UserID'}
Alternative approaches to using PX Policy involve writing custom code with an LAH, BLTH, or validation JavaScript on the Profile screen for the task (i.e. Modify Admin Task -> Find your task -> Tabs -> Profile -> Select your field).
In the validation script you can use the following example that uses regular expression to replace the trailing space characters with empty strings, hence eliminating the trailing spaces.
Function validate(FieldContext, attributeValue, changedValue, errorMessage) {
If (attributeValue.indexOf(" ") > -1) {
changedValue.reference = attributeValue.replace(/\s+|\s+$/g,"");
}
Return true;
}