SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [vlo].[mxpt_vlo_check_account_bs] @Mkey int, @Repid int, @Taskid int, @Audid int, @Bres varchar(64) OUTPUT AS declare @Lnum int declare @Lnum2 int declare @LrepNum int DECLARE @LogText varchar(255) DECLARE @LattrName varchar(255) DECLARE @LrepName varchar(255) DECLARE @LattrId int DECLARE @LmsKey int DECLARE @Ids int DECLARE @EntrytypeId int DECLARE @sapid varchar(20) SET @sapid = (SELECT sapid FROM vlo.vids_IdentityMaster WHERE Mskey = @Mkey) IF @sapid IS NULL SET @sapid = 'Not Found - ' + CONVERT(varchar,@Mkey); set @LrepName = (select rep_name from MC_REPOSITORY where rep_id = ( select repository from MXP_Audit where auditID = @Audid )) IF @LrepName IS NULL BEGIN SET @Bres = '0'; SET @LogText = @sapid + ' ERROR!Repository does not exist ' + CONVERT(varchar,@Audid) execute mc_write_syslog @LogText,'',1,'',0 return END set @LmsKey = @Mkey set @Ids = (select top 1 is_id from mxi_values where mskey=@LmsKey) IF @Ids IS NULL BEGIN SET @Bres = '0'; SET @LogText = @sapid + ' ERROR!Entry does not exist ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 return END set @EntrytypeId = (select ocId FROM mxi_objectclasses WHERE ocIsId=@Ids AND Upper(ocName) = (select searchvalue from mxiv_sentries where mskey=@LmsKey and attrname='MX_ENTRYTYPE')) set @LattrName = 'ACCOUNT' + @LrepName set @Lnum = (select count (*) from mxiv_sentries where ATTRNAME = @LattrName and mskey = @Mkey) set @LattrName = 'TEMPACCOUNT' + @LrepName set @Lnum2 = (select count (*) from mxiv_sentries where ATTRNAME = @LattrName and mskey = @Mkey) -- SET @LogText = 'Check for account flags: '+convert(varchar, @Lnum)+' and '+convert(varchar, @Lnum2) -- execute mc_write_syslog @LogText,'',1,'',0 IF @Lnum>0 BEGIN -- account is already completely created. set @Bres = '0'; SET @LogText = @sapid + ' Account is already created ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 END ELSE BEGIN -- account is not yet completely created check with the help of TEMPACCOUNT -- if account is in the state of being created IF @Lnum2>0 BEGIN -- account is in the state of being created set @Bres = '0'; SET @LogText = @sapid + ' Account is in the state of being created ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 END ELSE BEGIN declare @Presedence int, @Attrid int, @Perr int, @attrVal varchar(255) SET @LogText = @sapid + ' Account has to be created ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 -- account is not created and not in the state of being created. -- here we have to set the TEMPACCOUNT FLAG to indicate that the account -- creation process is now starting set @LattrName = 'TEMPACCOUNT' + @LrepName -- Create attribute if it does not exist exec mxi_setschemaattribute @Ids,@LattrName,1,1,-1,30,NULL,NULL,NULL,@LattrName, 1,1,0,@LattrName,0,@Attrid output,@Perr output; IF (@Perr=0) AND (@EntrytypeId>0) BEGIN -- Add attribute to entry type exec mxi_setocattr @Ids,@EntrytypeId,0,@LattrName,0,0 END IF @Perr>0 BEGIN SET @Bres = '0'; SET @LogText = @sapid + ' ERROR!Account attribute creation failed ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 return END set @attrVal = 'TEMP_CREATION' exec mxi_xset_attr_value @LmsKey, @LattrName, @attrVal ,NULL,NULL,0,NULL,0,-1,NULL, @Presedence output,@Attrid output,@Audid output,@Perr output IF @Perr>0 BEGIN SET @Bres = '0'; SET @LogText = @sapid + ' ERROR!Setting account value failed ' + @LrepName execute mc_write_syslog @LogText,'',1,'',0 return END set @Bres = '1'; END END GO