Script Repository


Convert the first character of a property value to uppercase

February 24, 2021
500

The script converts the first value character of the specified properties to uppercase. If a value contains multiple parts separated by spaces, the first character of each part will be converted. The script can be used only in a business rule triggering Before creating a user or Before updating a user.

Edit Remove
PowerShell
$propertiesToCheck = @("givenName", "sn", "name", "displayName") # TODO: modify me

function FixString ($string)
{
    return $string.SubString(0, 1).ToUpper() + $string.SubString(1).ToLower()
}

foreach ($propertyName in $propertiesToCheck)
{
    # Get property value
    $value = $Context.GetModifiedPropertyValue($propertyName)
    if ([System.String]::IsNullOrEmpty($value))
    {
        continue
    }
   
    # Convert first value character to uppercase
    if ($value -match " ")
    {
        $valueParts = $value.Split(" ") | %%{FixString $_}
        $value = [System.String]::Join(" ", $valueParts)
    }
    else
    {
        $value = FixString $value
    }
   
    # Update property
    $Context.SetModifiedPropertyValue($propertyName, $value)
}


Comments ( 0 )
No results found.
Leave a comment