SQL Loader : Update with FirstName creating a new Account while provisioning

Hi Team, whenever I am updating the Firstname , a new account is getting created instead of updating. But when I update any other attribute, it’s getting successfully updated. I am not neither using Firstname as Account ID nor in Correlation Logic.

Hi @sanjaybudhiraja ,

Can you please let us know what is the operation you are using in endpoint also please refer update-user | SailPoint Developer Community for updating existing user. let us know of you get any issue.

Hi Dheeraj, I am using SQL Loader connector to provision accounts, So I am using JDBC provisioning rule to update User. Though all other attributes are getting updated except for FirstName.

Hi @sanjaybudhiraja,

Did you added the condition in the rule to check if account already exists or not on account create operation.

Another thing, I want you to check is Admin → Identities → Activities and see which operation is being created.

Hi Animesh, I didnot add this condition and it’s create operation in Activities. . Can you share an example for this please ?

This is how I have written :
</>
if ( accounts != null )
{
for ( ProvisioningPlan.AccountRequest account : accounts )
{
String nativeIdentity = “”;
log.error(“getNativeIdentity value:” +account.getNativeIdentity());
if(account.getNativeIdentity() !=null)
{
nativeIdentity = account.getNativeIdentity();
log.error(“Print nativeIdentity before create or update:” +nativeIdentity);
log.error(“entering AccountRequest here:”+ account);

           if (account.getOperation().equals(ProvisioningPlan.AccountRequest.Operation.Create)) 
	       {
	        log.error("entering create loop here");
            PreparedStatement createstatement = connection.prepareStatement( Create_Query );
		    log.error("entering createstatement loop here: "+createstatement);
			try
			{
			  log.error("Print nativeIdentity before create:" +nativeIdentity);
  	          createstatement.setString(1, nativeIdentity);
		      log.error("Entering person id");

</>

The condition is quite easy to add

if (AccountRequest.Operation.Create.equals(account.getOperation())) {
    // Check if the account already exists based on the login
    PreparedStatement checkStatement = connection.prepareStatement("SELECT COUNT(*) FROM users WHERE login = ?");
    checkStatement.setString(1, (String) account.getNativeIdentity());
    ResultSet resultSet = checkStatement.executeQuery();
    resultSet.next();
    int count = resultSet.getInt(1);
    if (count == 0) {
        // Account does not exist, proceed with insertion
    } else {
        // Account already exists
    }

Though this won’t update the firstname, you can loop through the provisioning plan in else condition to update the attribute.

Note:- I am still not sure why create operation is created instead of modify.

Can you share how does your create query look like?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;
import sailpoint.api.SailPointContext;
import sailpoint.connector.JDBCConnector;
import sailpoint.object.Application;
import sailpoint.object.ProvisioningPlan;
import sailpoint.object.ProvisioningPlan.AccountRequest;
import sailpoint.object.ProvisioningPlan.AttributeRequest;
import sailpoint.object.ProvisioningPlan.PermissionRequest;
import sailpoint.object.ProvisioningResult;
import sailpoint.object.Schema;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.sql.Timestamp;
  
public String getAttributeRequestValue(AccountRequest acctReq, String attribute) 
 {
    log.error("AccountRequest starting");
    if ( acctReq != null ) 
	{
	  log.debug("acctReq is not null");
      AttributeRequest attrReq = acctReq.getAttributeRequest(attribute);
	  log.debug("attrReq value:" +attrReq);
      if ( attrReq != null ) 
	  {
        return attrReq.getValue();
      }
    }
    return null;
 }

    ProvisioningResult result = new ProvisioningResult();
    log.error("result at the start:" +result);
  
    String Create_Query ="insert into [ZTST_Alma_UpdateTest] ([StaffID], [Title], [FirstName], [LastName], [Faculty], [Department], [Uname], [LeaveDate], [EmployeeSubGroup], [Email], [Phone], [Stat] ) values (?,?,?,?,?,?,?,?,?,?,?,?)";

	
	public String getModifySqlQuery(List attributeRequestsList, String nativeIdentity) 
	{
		log.error("************Entering getModifySqlQuery method******************");
		String basesql = "update [ZTST_Alma_UpdateTest] SET ";
		String sqlquery = basesql;
		String values = "";
		String nullString = null;
		for (AttributeRequest attributeRequest : attributeRequestsList) {
		    log.error("Name value:" +attributeRequest.getName() + attributeRequest.getValue());
		    if ((attributeRequest.getValue() != nullString) && (attributeRequest.getName().contains("Email")))
			{
			  sqlquery += attributeRequest.getName() + "='"+ attributeRequest.getValue() +"' ,";
			  log.error("Print sqlquery:" +sqlquery);
			}
			else
			{
			  log.error("Null value in :" + attributeRequest.getValue());
			}
		}
		if (sqlquery.equals(basesql))
		{
		  log.error("No field is modified - do not execute update");
		  return nullString;
		}
		else
		{
		  sqlquery = sqlquery.substring(0, sqlquery.lastIndexOf(","));
		  sqlquery += "where StaffId='" + nativeIdentity + "'";
		  log.error("getModifySqlQuery*****Query" + sqlquery);
		  return sqlquery;
		}
	}

   
    try
     {
      if ( plan != null ) 
      {
        List accounts = plan.getAccountRequests();
	    log.error("Print list of accounts :" + accounts);
	
        if ( accounts != null ) 
	    {
         for ( ProvisioningPlan.AccountRequest account : accounts ) 
	      {
	        String nativeIdentity = "";
		    log.error("getNativeIdentity value:" +account.getNativeIdentity());
	        if(account.getNativeIdentity() !=null) 
		    {
		       nativeIdentity = account.getNativeIdentity();
		       log.error("Print nativeIdentity before create or update:" +nativeIdentity);
	           log.error("entering AccountRequest here:"+ account);
       
               if (account.getOperation().equals(ProvisioningPlan.AccountRequest.Operation.Create)) 
		       {
		        log.error("entering create loop here");
                PreparedStatement createstatement = connection.prepareStatement( Create_Query );
			    log.error("entering createstatement loop here: "+createstatement);
			    
				try
				{
				  log.error("Print nativeIdentity before create:" +nativeIdentity);
	  	          createstatement.setString(1, nativeIdentity);
			      log.error("Entering person id");
			
			      String UniversityTitle = getAttributeRequestValue(account,"Title");
			      log.error("Print Title:" +Title);
                  createstatement.setString(2, UniversityTitle);
			
			      String loginDom = getAttributeRequestValue(account,"FirstName");
			      log.error("Print Login_domain:" +FirstName);
                  createstatement.setString(3, loginDom);
			
			      String Act = getAttributeRequestValue(account,"LastName");
			      log.error("Print Account :" +LastName );
                  createstatement.setString(4,Act );
			
			      String namee = getAttributeRequestValue(account,"Faculty");
			      log.error("Print namee:" +Faculty);
                  createstatement.setString(5,namee);
			
			      String dept = getAttributeRequestValue(account,"Department");
			      log.error("Print dept:" +Department);
                  createstatement.setString(6,dept);
			
			      String usertype = getAttributeRequestValue(account,"Uname");
			      log.error("Print user_type:" +Uname);
                  createstatement.setString(7,usertype);
			
			      String Ldate = getAttributeRequestValue(account,"LeaveDate");
			      log.error("Print LeaveDate:" + LeaveDate);
                  createstatement.setString(8, Ldate); 
		
			      String FacultyId = getAttributeRequestValue(account,"EmployeeSubGroup");
			      log.error("Print EmployeeSubGroup:" +EmployeeSubGroup);
                  createstatement.setString(9,FacultyId );
			
			      String email = getAttributeRequestValue(account,"Email");
			      log.error("Print Email:" + Email);
                  createstatement.setString(10,email );
			
	   		      String phone = getAttributeRequestValue(account,"Phone");
			      log.error("Print Phone:" + Phone);
                  createstatement.setString(11,phone );

				  String stat = getAttributeRequestValue(account,"Stat");
			      log.error("Print Stat:" + Stat);
                  createstatement.setString(12,stat );
			
                  createstatement.executeUpdate();
				  log.error("Print createstatement here:" +createstatement);
			      log.error("INSERT STATEMENT EXECUTED SUCCESSFULLY ");

                  result.setStatus( ProvisioningResult.STATUS_COMMITTED );
				}
				catch (SQLException e) 
				{
				    log.error("Create query error:" +e.getMessage());
					result.addError(e.getMessage());
					result.setStatus(ProvisioningResult.STATUS_FAILED);
				}
				finally
				{
					if( createstatement != null)
					{
						try 
						{
						    log.error("close createaccount statement");
							createstatement.close();
						}
						catch (SQLException e) 
						{
						   log.error("Close createaccount:" +e.getMessage());
						}
					}
				}
		       }
			   if (account.getOperation().equals(ProvisioningPlan.AccountRequest.Operation.Modify))
		       {
		        log.error("Update block execution started");
			    log.error("Print nativeIdentity in Update logic:" +nativeIdentity);        
			    
				String nullString = null;
				String modifyStr = "";
				List attributeModifyRequestsList = account.getAttributeRequests();
				List<String> table_columns = Arrays.asList("Title","FirstName","LastName","Faculty","Department","Uname","LeaveDate","EmployeeSubGroup","Email","Phone");
				log.error("Print attributeModifyRequestsList:" + attributeModifyRequestsList);
				
				/*String modifyStr = getModifySqlQuery(attributeModifyRequestsList,nativeIdentity);*/
				log.error("************Entering Build update sql query method******************");
		        String basesql = "update [ZTST_Alma_UpdateTest] SET ";
		        String sqlquery = basesql;
		        for (String str : table_columns) 
				{
				  String cValue = getAttributeRequestValue(account,str);
		          log.error("Column-Value:" +str +"-" + cValue);
		          if (cValue != nullString) 
			      {
			        sqlquery += str + "='"+ cValue +"' ,";
			        log.error("Print sqlquery:" +sqlquery);
			      } 
			      else
			      {
			        log.error("Null value in :" + str);
			      }
		        }
		        if (sqlquery.equals(basesql))
		        {
		            log.error("No field is modified - do not execute update");
		            modifyStr = nullString;
		        }
		        else
		        {
		            sqlquery = sqlquery.substring(0, sqlquery.lastIndexOf(","));
		            sqlquery += "where StaffID='" + nativeIdentity + "'";
		            log.error("getModifySqlQuery*****Query" + sqlquery);
		            modifyStr = sqlquery;
		        }
				
				if (modifyStr != nullString)
				{
				  PreparedStatement updatestatement = connection.prepareStatement( modifyStr );
			      log.error("entering updatestatement loop here: " +updatestatement);
				  try
				  {
		            updatestatement.executeUpdate();
		            log.error("UPDATE STATEMENT EXECUTED SUCCESSFULLY ");
		            result.setStatus( ProvisioningResult.STATUS_COMMITTED );  
				  }
				  catch (SQLException e) 
				  {
				      log.error("Update query error:" +e.getMessage());
					  result.addError(e.getMessage());
					  result.setStatus(ProvisioningResult.STATUS_FAILED);
				  }
				  finally
				  {
					  if( updatestatement != null)
					  {
						  try 
						  {
						      log.error("close updatestatement statement");
						  	  updatestatement.close();
						  }
						  catch (SQLException e) 
						  {
						     log.error("Close updatestatement:" +e.getMessage());
						  }
					  }
				  }
				}
               }
	        }
          }
       }
     }
	}
    catch (SQLException e) 
    {
       log.error("First Try exception:" + e.getMessage());
	   result.addError(e.getMessage());
	   result.setStatus(ProvisioningResult.STATUS_FAILED);
    }  
    return result;

Thanks for sharing the code… It seems like the INSERT query is executed in your rule, which means Create operation is triggered (as you have already noted earlier).

Can you share how the source is configured? Specifically, what account attributes are marked as Account ID and Account Name?

Still a mystery why Create Operation is triggered in Provisioning!!

I am myself confused why new account is getting created when an update of FirstName is performed.
Staff ID is the Account ID and Account Name.
Can you also share any JDBC provisioning rule where you have written create and modify ?
Thanks in anticipation.

This is a very strange behavior indeed!!

Are you able to create a duplicate source and check if the same behavior repeats?

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