0 votes

Hi

We've run into an issue a couple of time recently where people creating new starters are using copy and paste, but including whitespace at the beginning or end of the users names.

I've tried to mitigate this by adding the following to a script which is run before the user is created, but all I get is an error

#Remove leading and trailing whitespace from First, Last and Full name
$Properties = @("firstname","lastname","fullname")
foreach ($propertyName in $Properties) {
    $value = $Context.GetModifiedPropertyValue($propertyName)
    $removedWhitespaceValue = $value.trim()
    if ($value -ne $removedWhitespaceValue) { 
        $Context.LogMessage("Removing whitespace for '$propertyName'.", "Notification")
        $Context.SetModifiedPropertyValue($propertyName, $removedWhitespaceValue) 
    }
}

Is there an easy way to add validation to the fields to and remove any whitespace?

Thanks

by (2.0k points)

1 Answer

0 votes
by (289k points)
selected by
Best answer

Hello,

Have a look at the following tutorial: https://www.adaxes.com/tutorials_Simpli ... Script.htm. You need Example 5: Automatically remove spaces from the username.

0

Thanks very much, I'll work through that.

0

Hi

Turns out I was close with my first script, the issue was the attribute names I was using.
To my mind, the following is cleaner and easier to manage than duplicating the same code for each property.
This also allows for the cleanup of whitespace from the beginning and end of the users full name.

#Remove leading and trailing whitespace from First, Last and Full name, SAMAccountName and UserPrincipleName
$Properties = @("givenName","sn","cn","samAccountName","userPrincipalName")
foreach ($propertyName in $Properties) {
    #Get the property value
    $value = $Context.GetModifiedPropertyValue("$propertyName")
    #Trim the white space from the beginning and end
    $trimmedValue = $value.trim()
    $Context.LogMessage("Checking $propertyName for whitespace", "Information")
    #If the original and trimmed values don't match, there must be whitespace
    if ($value -ne $trimmedValue) {
        $Context.LogMessage("Removing whitespace for '$propertyName'.", "Information")
        #Write the trimmed value back to the property.
        $Context.SetModifiedPropertyValue("$propertyName", $trimmedValue) 
    }
}

Hope this helps someone :)

Matt

0

We faced the same issue, and we are using a regex to deny starting/ending white chars:

^[^\s].*[^\s]$

Related questions

0 votes
1 answer

I have a customized Web form used to create a Non-Employee that contains fields that are required. When I leave some of the fields blank and select the "Create" button, ... if the form still has required fields that are blank? Screen shots below. Thanks...

asked Jul 21, 2015 by sandramnc (870 points)
0 votes
1 answer

Hi all, I am not a user of Adaxes but I wanted to post this challenge that I'm having and would like to see if others are using Adaxes to resolve this. OK so ... that the manager has validated for the month. Does Adaxes do something like this? Thanks, Chris

asked Jan 28, 2015 by tke402 (20 points)
0 votes
1 answer

Hi I had followed the steps listed under the url: http://www.adaxes.com/tutorials_Simplif ... Script.htm to validate EmployeeID field, to check for "-". How come during ... system still let me create the new user account even though I purposely entered "-" ?

asked Nov 6, 2013 by alextan26 (20 points)
0 votes
1 answer

Is it possible to have one field in a "Create User" request to be required depending on the value of another. For instance, if i selected the EmployeeType as staff, the ... but i wanted to see if there was a neater way to provide the pre-submit validation.

asked Sep 28, 2012 by chriswharton22 (60 points)
0 votes
1 answer

When adding Mobile Phone to a custom form, it seems to also inlcude "Mobile Phone (Other)" which we do not want visible in the form. Is there a way to separate the two or simply hide Mobile Phone (Other)?

asked Nov 11 by msheppard (470 points)
3,552 questions
3,242 answers
8,243 comments
547,831 users