To simplify the process of creating a new user and avoid inevitable errors when users type in a department manually, you can allow users to specify a department by simply checking it in the list of available departments. For this purpose, you need to:
- List all possible departments on the page for creating new users as boolean fields. For this purpose, you can use Adaxes custom attributes that can store boolean values (CustomAttributeBoolean1 - CustomAttributeBoolean25). For information on how to add the attributes to the form for creating new users, see the Customize Forms for User Creation and Editing Tutorial (starting from step 6).
- Rename the properties to resemble the names of the departments that each of them represents. For information on how to do this, see Customizing Display Names for AD Properties.
- Create a business rule that will run the below script to automatically update the Department attribute based on which departments are selected. How to automatically run scripts after creating a user.
Note: Alternatively, you can specify a list of departments so users can select one form a drop-down list.
Parameters:
- $departmentInfos - specifies a table that matches names of boolean attributes to the appropriate departments and their short names.
PowerShell
$departmentInfos = @{
"adm-CustomAttributeBoolean1" = "Administrative", "Admin";
"adm-CustomAttributeBoolean2" = "Sales Department", "Sales";
"adm-CustomAttributeBoolean3" = "IT Department", "IT";
} # TODO: modify me
# Example: $departmentInfos = @{"" = "full name of the department", "abbreviation";}
function UpdateDepartment($value)
{
$Context.TargetObject.Put("department", $value)
$Context.TargetObject.SetInfo()
}
$enabledProperties = @()
foreach ($propertyName in $departmentInfos.Keys)
{
try
{
$result = $Context.TargetObject.Get($propertyName)
}
catch
{
continue
}
if (!$result)
{
continue
}
$enabledProperties += $propertyName
}
if ($enabledProperties -eq $NULL)
{
return
}
# Only 1 property is enabled
if ($enabledProperties.Length -eq 1)
{
$propertyName = $enabledProperties[0]
$values = $departmentInfos[$propertyName]
UpdateDepartment $values[0]
return
}
$department = $NULL
foreach ($propertyName in $enabledProperties)
{
$values = $departmentInfos[$propertyName]
$department += $values[1] + ", "
}
# Update department
UpdateDepartment $department.TrimEnd(@(",", " "))