Email creation in provisioning

Which IIQ version are you inquiring about?

8.4… I will trying to provision an email generator for data which is coming from HR system below is my code but i getting error
the application script threw an exception: java.lang.nullpointerexception: Null pointer in method Invication BSF info: email creation at line: 0 column: 0 cloumn No

import sailpoint.object.;
import java.util.
;
import java.io.*;

boolean checkUniquemail(String uniqueEmail) {
QueryOptions queryOption = new QueryOptions();
queryOption.addFilter(Filter.eq(“email”,uniqueEmail));
Iterator identityIterator = context.search(Identity.class, queryOption);
while ( identityIterator.hasNext() ) {
return false;
}
return true;
}

String uniqueEmail=“”;
int increment=0;
String domain="@test.com"; // change to actual domain
String firstName=“”;
String lastName=“”;

// Update the block to add your logic for email generation
firstName = identity.getAttribute(“firstname”); // change firstname to first name attribute value from identity mapping

lastName = identity.getAttribute(“lastname”);; // change lastname to last name attribute value from identity mapping
lastName= lastName.replaceAll(“[\[.\]+]”, “”);

uniqueEmail = firstName + lastName + domain;
/////////////////

while (!checkUniquemail(uniqueEmail)) {
increment++;
uniqueEmail = uniqueEmail.substring(0,uniqueEmail.indexOf(‘@’))+ increment + domain;
}

return uniqueEmail.trim().toLowerCase();

1 Like

This means there is a syntax error in your code:
for example: lastName = identity.getAttribute(“lastname”);; should contain one semicolon instead of 2.

I’ve remove the semi colon but still same error.
Then I added
boolean checkUniquemail(String uniqueEmail) {
If( uniqueEmail == null)
return null
remaining code
}
remaining code…
but still same issue

Add Null checks at below lines

Summary

if(Util.isNotNullOrEmpty(lastName))
lastName= lastName.replaceAll(“[[.]+]”, “”);

if(Util.isNotNullOrEmpty(lastName))
uniqueEmail = firstName + lastName + domain;
else
uniqueEmail = firstName + domain;

I think there might be a data issue where last name is coming as null

You can actually add similar check to first name as well and try
Note - Add import statement for Util

import sailpoint.tools.Util;

Hi @nitindpraj ,

It looks like you have not pasted the complete code. It is difficult to check and let you know where you are getting this error. Though you can try by putting null checks as others suggested. Besides this, while checking the logs, if you come down a little more, you will get more details, like from which object reference you are trying to call which method which is throwing the expectation. Please try and let us know.

Hi @nitindpraj,

Try with this code

 import sailpoint.object.Filter;
  import sailpoint.object.Identity;
  import sailpoint.tools.GeneralException;
  import sailpoint.object.QueryOptions;
  import sailpoint.tools.Util;

  boolean checkUniquemail(String uniqueEmail) {
    QueryOptions queryOption = new QueryOptions();
    queryOption.addFilter(Filter.eq("email",uniqueEmail));
    Iterator identityIterator = context.search(Identity.class, queryOption);
    while ( identityIterator.hasNext() ) {
      return false;
    }
    return true;
  }

  String uniqueEmail="";
  int increment=0;
  String domain="@test.com";
  String firstName="";
  String lastName="";

  firstName = identity.getAttribute("firstname");
  lastName = identity.getAttribute("lastname");


  if (Util.isNotNullOrEmpty(lastName)) {
    lastName= lastName.replaceAll("[[.]+]", "");
  }

  if (Util.isNotNullOrEmpty(firstName) && Util.isNotNullOrEmpty(lastName)) {
    uniqueEmail = firstName + lastName + domain;
  } else if (Util.isNotNullOrEmpty(firstName)) {
    uniqueEmail = firstName + domain;
  } else if (Util.isNotNullOrEmpty(lastName)) {
    uniqueEmail = lastName + domain;
  } else {
    throw new IllegalArgumentException("Both first name and last name cannot be null or empty");
  }

  while (!checkUniquemail(uniqueEmail)) {
    increment++;
    uniqueEmail = uniqueEmail.substring(0,uniqueEmail.indexOf('@'))+ increment + domain;
  }
  return uniqueEmail.trim().toLowerCase();

I tried this code but getting below error
bean shell Script error: bsh.parseExecption: parse at line 31. cloumn 44. Encountered; BSF info: Emation creation at line: 0 column: cloumn No.

Replace the && with && on line no 31 like below and try

 if (Util.isNotNullOrEmpty(firstName) && Util.isNotNullOrEmpty(lastName))

Looks syntactical error at line number 32. Please check at line number 32 and provide a screenshot of it. Will check it. Take the code from source and put in notepad++ or any editor. and check at line 32. You will get exactly where the issue you are getting.

Could you please share the code which you are getting this error?

It’s a same code which you shared above and I;ve pasted it in notepad++.

Are you change the domain variable or using “@test.com” as domain?

No… I have changed it to my domain name

Looks like issue with domain variable. How are you declaring the domain variable?

@Arun-Kumar Thank you for assistance below code is working.
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.tools.GeneralException;
import sailpoint.object.QueryOptions;
import sailpoint.tools.Util;

boolean checkUniquemail(String uniqueEmail) {
QueryOptions queryOption = new QueryOptions();
queryOption.addFilter(Filter.eq(“email”,uniqueEmail));
Iterator identityIterator = context.search(Identity.class, queryOption);
while ( identityIterator.hasNext() ) {
return false;
}
return true;
}

String uniqueEmail=“”;
int increment=0;
String domain="@NP.XXXX.com";
String firstName=“”;
String lastName=“”;

firstName = identity.getAttribute(“firstname”);
lastName = identity.getAttribute(“lastname”);

if (Util.isNotNullOrEmpty(lastName)) {
lastName= lastName.replaceAll(“[[.]+]”, “”);
}

if (Util.isNotNullOrEmpty(firstName) @and Util.isNotNullOrEmpty(lastName)) {
uniqueEmail = firstName + lastName + domain;
} else if (Util.isNotNullOrEmpty(firstName)) {
uniqueEmail = firstName + domain;
} else if (Util.isNotNullOrEmpty(lastName)) {
uniqueEmail = lastName + domain;
} else {
throw new IllegalArgumentException(“Both first name and last name cannot be null or empty”);
}

while (!checkUniquemail(uniqueEmail)) {
increment++;
uniqueEmail = uniqueEmail.substring(0,uniqueEmail.indexOf(‘@’))+ increment + domain;
}
return uniqueEmail.trim().toLowerCase();

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