Before Provisioning DisplayName Changecloud rule

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule name="AD Accounts" type="BeforeProvisioning">
    <Description>Handle AD name and OU changes. Remove all groups on termination.</Description>
    <Source><![CDATA[
 
        import java.util.Date;
        import java.text.SimpleDateFormat;
        import sailpoint.api.SailPointContext;
        import sailpoint.object.ProvisioningPlan;
        import sailpoint.object.ProvisioningPlan.Operation;
        import sailpoint.object.ProvisioningPlan.AccountRequest;
        import sailpoint.object.ProvisioningPlan.AttributeRequest;
        import sailpoint.object.QueryOptions;
        import sailpoint.object.Identity;
        import sailpoint.connector.Connector;
        import sailpoint.object.Application;
        import sailpoint.object.*;
        import sailpoint.api.IdentityService;
        import java.util.ArrayList;
        import java.util.Arrays;
        import java.util.Iterator;
        import java.util.List;
        import java.util.regex.Pattern;
        import java.text.Normalizer;
        import java.text.Normalizer.Form;
        import sailpoint.object.*;
        import sailpoint.api.*;
        import org.apache.commons.lang.StringUtils;
        import sailpoint.rule.Account;
        import sailpoint.tools.GeneralException;
 
//Name change use case updates
		
        AttributeRequest attributeRequestGivenName = accountRequest.getAttributeRequest("givenName");
        AttributeRequest attrRequestSN = accountRequest.getAttributeRequest("sn");

        if (attributeRequestGivenName != null || attrRequestSN != null)
                {
        Identity id = plan.getIdentity();
        String firstName=id.getFirstname();
        String middleName=id.getStringAttribute("middleName");

        String lastName=id.getLastname();
        firstName=sanitizeData(firstName);
        lastName=sanitizeData(lastName);
        middleName=sanitizeData(middleName);

        String newSamAccountName = "";
        String proposedSamAccountName = "";
        String result="";
		result=id.getAttribute("firstletterfirstname");
		String indexoffirstname= "";
		
        if ((firstName!=null))
                {
        indexoffirstname=StringUtils.substring(firstName, 0, 1);
				}
				//Comparing firstname first letter with AD firstname attribute
				
				if(result!=null && result!=indexoffirstname && indexoffirstname!=null)
				{

        //Change User DN
			if ( (id != null) && (id.getAttribute("ou") != null) )
                {
            String ou = id.getAttribute("ou");
			accountRequest.add(newAttributeRequest("AC_NewParent", ou));
                }

        //Change sAMAccountName
        

			if ((firstName!=null) && (lastName!=null))
                {
        String firstInitial=StringUtils.substring(firstName, 0, 1);
        proposedSamAccountName = firstInitial+lastName;
                if(idn.isUniqueLDAPValue(identity.getName(),application.getName(),"sAMAccountName",proposedSamAccountName)){
        newSamAccountName = proposedSamAccountName;
                } else if(firstName!=null && lastName!=null && middleName!=null)
{
        String middleName=id.getStringAttribute("middleName");
        middleName=sanitizeData(middleName);
        String middleInitial = StringUtils.substring(middleName, 0, 1);
        proposedSamAccountName = firstInitial+middleInitial+lastName;
                    if(idn.isUniqueLDAPValue(identity.getName(),application.getName(),"sAMAccountName",proposedSamAccountName)){
        newSamAccountName = proposedSamAccountName;
                    } else {
        newSamAccountName = returnUniqueSamAccountName(identity.getName(), application.getName(),"sAMAccountName",proposedSamAccountName,idn);
                }
                } else {
        newSamAccountName = returnUniqueSamAccountName(identity.getName(), application.getName(),"sAMAccountName",proposedSamAccountName,idn);
                }
                }

                //Assign new samAccountName
                accountRequest.add(newAttributeRequest("sAMAccountName", newSamAccountName));

                //Assign new UPN
                accountRequest.add(newAttributeRequest("userPrincipalName", newSamAccountName+"@xyz.com"));

        //Assign new CN
        String cn = id.getAttribute("displayNameAd");
        String finalCN = returnUniqueCN(id.getName(), application.getName(), "cn", cn, idn);

			if(finalCN != null){

                accountRequest.add(newAttributeRequest("AC_NewName", finalCN));

            }
            //Assign new mail
            accountRequest.add(newAttributeRequest("mail", newSamAccountName+"xyz.com"));

        //Update proxyAddresses
        Account acct = idn.getFirstAccount("Active Directory", identity.getName());
        List proxyAddresses = idn.getRawAccountAttribute(acct,"proxyAddresses");
			if(proxyAddresses == null){
        proxyAddresses = new ArrayList();
			}
                    proxyAddresses.add("smtp:"+newSamAccountName+"@xyz.com");
			accountRequest.add(newAttributeRequest("proxyAddresses", proxyAddresses));
				}
                }

                }
                }
                accreqs.add(accountRequest);
    }
            plan.setAccountRequests(accreqs);
}
        }
        
		 ]]></Source>
</Rule>
          ]]></Source>
</Rule>

I need to modify this rule to check if the lastname attribute has been changed on Auth Source

if lastname is changed then the code will execute else attribute sync will perform the the sync for firstname and middlename sync to AD.

challenge here is : How to check if the previousfamilyName != currentfamilyName.( it needs to be addted at line if(result!=null && result!=indexoffirstname && indexoffirstname!=null) ref Rule)

I tried with below transform though previous value is not been fetched.

{
"id": "1c981b24-ffd5-470c-aefd-35d1a427398f",
"name": "LastnamePrevoiusvalue",
"type": "lower",
"attributes": {
"input": {
"attributes": {
"ignoreErrors": "true",
"values": [
"$oldValue",
{
"attributes": {
"attributeName": "familyName",
"sourceName": "ADP"
},
"type": "accountAttribute"
},
"none"
]
},
"type": "firstValid"
}
},
"internal": false
},

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.