We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Convert the first character of a property value to uppercase

February 24, 2021 Views: 1541

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers