Hello,
A Business Rule triggered after renaming a user won't help you in this case. The thing is that renaming a user means changing a user's Name property. The Name property specifies sets a name under which a user account appears in Active Directory, for example, John Doe. A username specifies the name under which a user can log in to Active Directory, for example, jdoe@example.com or EXAMPLE\jdoe. That is, a Business Rule triggered after renaming a user will be executed only when the Name property is changed, but not when you set a different username.
To achieve what you want, you'll actually need not 1, but 2 Business Rules. One of the Business Rules will be triggered before updating a user. If an operation changes a username and an e-mail address of a user account, the Business Rule will save the old username and e-mail in certain Adaxes custom attributes of the user account, for example, CustomAttributeText1 and CustomAttributeText2. Such attributes are not stored in Active Directory, but can be used the same as any other attributes of AD objects.
Another Business Rule triggered after updating a user will send the e-mail message. The old values for the properties will be taken from the Adaxes custom attributes that you used in the 1st Business Rule. The new values for the properties will be taken from their current values after the operation is complete.
To create such Business Rules:
I. Create Business Rule triggered before updating username and e-mail to save old values to custom attributes
A Business Rule created per the following instructions will save the old username to the CustomAttributeText1 property, and the old e-mail to the CustomAttributeText2 property.
-
Create a new Business Rule.
-
On Step 2 of the Create Business Rule wizard, select User and Before Updating a User.
-
On Step 3, add the Run a program or PowerShell script action and paste the following script in the Script field:
# Get current username and mail property values
$currentUsername = $Context.TargetObject.Get("sAMAccountName")
$currentMail = $Context.TargetObject.Get("mail")
# Save current username and mail to the custom attributes
$Context.TargetObject.Put("adm-CustomAttributeText1", $currentUsername)
$Context.TargetObject.Put("adm-CustomAttributeText2", $currentMail)
$Context.TargetObject.SetInfo()
-
Enter a short description for the script and click OK.
-
Now, you need to add conditions for the Business Rule to be triggered only when username and e-mail are changed. For this purpose, double-click Always.
-
Select the If <property> Changed condition type.
-
Specify If User Logon Name has changed.
-
Click OK.
-
Right-click the condition that you've just added and click Add New Condition.
-
Select the If <property> Changed condition type.
-
Specify If Email has changed.
-
Click OK and finish creation of the Business Rule.
Now, in a Business Rule triggered after updating a user, you can use value references to insert the old and the new values for the properties in the e-mail template. To insert the old values, use value references for the virtual attributes that you used, e.g. %adm-CustomAttributeText1% and %adm-CustomAttributeText2%. To get the new values, use the %username% and %mail% value references. Here's a sample mail template:
The Business Rule that you need to configure will look something like this: