Random number is generating in mailNickName

Based on the below rule, I am generating mailnickname first name first letter middle name (if it exists) first-letter and lastname, but it is generating a random number like 160Tim, as shown in the screenshot below.

image

In user details tab first name middlename and last name

Any idea please.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC 'sailpoint.dtd' 'sailpoint.dtd'>
<Rule language='beanshell' name='Get Unique Mail Nickname' type='AttributeGenerator' >
	<Description>Checks for mailnickname uniqueness across all Active Directory Domains</Description>
	<Source><![CDATA[


import sailpoint.object.*;
import sailpoint.api.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;


// Used to generate a unique Mail Nickname ex. bcsmith, bsmith1, bsmith2 etc


public boolean isUnique (String value) {
    boolean isValueUnique = false;
    List sourceList = new ArrayList(Arrays.asList(new String[]{"39485455ca984adcafffb4c165dd2ec3", "7d9a231ce021467b9c88135e22e0c9d0"}));
      
    List searchValue = new ArrayList(Arrays.asList(new String[]{value}));
    
    try{					
        int identityCount = idn.attrSearchCountAccounts(sourceList, "mailNickname", "StartsWith", searchValue);
        
        if(identityCount == 0)
            isValueUnique = true;			  		
    } 
    catch(Exception e){
        log.debug("SLHS Get Unique Mail Nickname Rule: Error Occurred during isUnique check : " + e);
        return false;
    }
    return isValueUnique;
}

String mailnickname = "";

String firstName = null != identity.getStringAttribute("firstname") ? identity.getStringAttribute("firstname") : "";
String lastName = null != identity.getStringAttribute("lastname") ? identity.getStringAttribute("lastname").replaceAll("[^a-zA-Z]", "") : "";
String middleName = null != identity.getStringAttribute("middleName") ? identity.getStringAttribute("middleName") : "";

if(!firstName.isEmpty() && !middleName.isEmpty() && !lastName.isEmpty()){
	mailnickname = firstName.charAt(0)+middleName.charAt(0)+lastName;
}
if(!firstName.isEmpty() && middleName.isEmpty() && !lastName.isEmpty()){
	mailnickname = firstName.charAt(0)+lastName;
}
if(firstName.isEmpty() && !middleName.isEmpty() && !lastName.isEmpty()){
	mailnickname = middleName.charAt(0)+lastName;
}
if(firstName.isEmpty() && middleName.isEmpty() && !lastName.isEmpty()){
	mailnickname = lastName;
}



// Check if original without counter is unique
if (isUnique(mailnickname)) {
    return mailnickname;
}

// Check mailnickname{counter} until unique
int iteration = 1;
int maxIteration = 10000;
while (iteration < maxIteration) {
            
    if (isUnique(mailnickname + iteration)) {
        return mailnickname + iteration;
    }
    
    iteration++;
}
return null;



]]></Source>
</Rule>

Hi @pkumar22
Can you ask the same question in the IIQ Discussions and Questions category?

This Ambassador category is more for questions about Ambassadors, not about the products :stuck_out_tongue_winking_eye:

– Remold

Can you share the screenshot of how Create Provisioning Policy is set for this particular attribute? ie Source > Accounts tab > Create Profile

1 Like

Here you can see

1 Like

firstName.charAt(0)

This returns a char and not String so while appending that it’s taking char value and not String. Please modify the lines in your code as follows and that will work :

mailnickname = β€œβ€ + firstName.charAt(0) + middleName.charAt(0) + lastName;

3 Likes

Hi @pkumar22

Based on your logic your expected output should be β€œSMTim”.
Since you are getting the character instead of String I can see that it is taking the ASCII value for SM and returning it as β€œ160Tim”

  • β€˜S’ has an ASCII value of 83
  • β€˜M’ has an ASCII value of 77

So you need to modify the code accordingly

3 Likes

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