This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADSAccount.CN Template issue

Hey Folks,

I am having a weird issue with template updates on ADSaccount CN created as part of an account definition.

Breakdown is as follows:

  • Account Definition SO is created.
  • Manage level SO FM is created.
  • Account Definition is assigned to Business Role.
  • Custom templates created to properly populate CN and SAMACCOUNTNAME.

When the role is selected as the person's primary biz role, the CN and SAMACCOUNTNAME are properly pre-pended with an "SO-" with the account creation.

The strange thing is that If I look at the object in manager and re-apply the template, the CN changes to a string of "SO-SO-SO-SO-SO" to the max length of the field it seems.

I am including the edited custom template code below (my custom code is between lines (25-47):

 

 

If Not CBool(Variables("FULLSYNC")) AndAlso Not ($cn$).Contains(Chr(10)) Then
Dim CN, CNfix, DNold, DNnew,Domain, wherePart As String
Dim i As Integer
Dim f As ISqlFormatter = Connection.SqlFormatter

If $Givenname$ <> $Givenname[o]$ Or $Surname$ <> $Surname[o]$ Then
If $Givenname$<>"" AndAlso $Surname$<>"" Then
CN = $Surname$ & " " & $Givenname$
ElseIf $Givenname$<>"" Then
CN = $Givenname$
ElseIf $Surname$<>"" Then
CN = $Surname$
Else
CN = $cn$
End If
Else
CN = $cn$
End If

Dim cnLen as Integer = Base.TableDef.Columns("CN").MaxLen
CN = VID_Left(CN, cnLen)

'=> Check for Account Definitions and set CN based on Account Definition Requirements.

select case $FK(UID_TSBBehavior).Ident_TSBBehavior$.ToUpper()

'=> BXIILAB SU Account CN
case "ELV FM SU ACCOUNT BXIILAB"
CN = "SU" + "-" + VID_Left(CN, (cnLen -4))

'=> BXIILAB SO Account CN
case "ELV FM SO ACCOUNT BXIILAB"
CN = "SO" + "-" + VID_Left(CN, (cnLen -4))

'=> BXIILAB SG Account CN
case "ELV FM SG ACCOUNT BXIILAB"
CN = "SG" + "-" + VID_Left(CN, (cnLen -4))

'=> BXIILAB DA Account CN

case "ELV FM DA ACCOUNT BXIILAB"
CN = "DA" + "-" + VID_Left(CN, (cnLen -4))

case else
CN = VID_Left(CN, cnLen)

end select

If $cn[o]$<>CN Or $UID_ADSContainer[o]$<>$UID_ADSContainer$ Then
i=1
CNFix = CN
If $UID_ADSContainer[o]$ <> "" Then
DNold = $FK(UID_ADSContainer[o]).DistinguishedName$
Else
DNold = $FK(UID_ADSDomain[o]).DistinguishedName$
End If
If $UID_ADSContainer$ <> "" Then
DNnew = $FK(UID_ADSContainer).DistinguishedName$
Else
DNnew = $FK(UID_ADSDomain).DistinguishedName$
End If
Domain = $UID_ADSDomain$

If DNold <> "" And DNold <> DNnew Then
wherePart = f.OrRelation( _
f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
)
Else
wherePart = f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
End If

Do While Connection.Exists( "ADSAccount", _
f.AndRelation( _
f.UidComparison("UID_ADSAccount", $UID_ADSAccount$, CompareOperator.NotEqual), _
f.UidComparison("UID_ADSDomain", Domain), _
wherePart _
))

CN = VID_Left(CNfix, cnLen - (1 + CStr(i).Length)) & "_" & i

If DNold <> "" And DNold <> DNnew Then
wherePart = f.OrRelation( _
f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
)
Else
wherePart = f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
End If

i=i+1
Loop
End If
Value = CN
End If

I am hoping that I am totally missing something obvious and that it is not some bug.

Thanks for the help!

  • This feels like a code bug in your template. Have you tried running through it with the system debugger?
  • Hey George,

    I am currently working in Designer and Manager and have not braved cracking this open in Studio.

    Do you think that is my only path to discovering what is happening here? I will give it a shot but I got a little confused watching the scripting videos with regards to setting this up.

    I can give it a crack though. Any other thoughts while I work that through?
  • You add your prefix to the CN regardless if the prefix is already there. This leads to the issue that the check against a changed CN in line 49 will always be true and this occurs each an every time your template is triggered.
  • Thanks Markus, I just changed the logic to just use the surname and givenName to get this done. Works fine now.
  • If Not CBool(Variables("FULLSYNC")) AndAlso Not ($cn$).Contains(Chr(10)) Then
    	Dim CN, CNfix, DNold, DNnew,Domain, wherePart As String
    	Dim i As Integer
    	Dim f As ISqlFormatter = Connection.SqlFormatter
    	Dim CurrentEnvironment as String = Connection.GetConfigParm("Custom\CurrentEnvironment")
    	Dim cnPostfix as String = connection.GetConfigParm("Custom\" & CurrentEnvironment & "\TargetSystem\ADS\Accounts\PrivilegedAccount\" & $FK(UID_TSBAccountDef).CustomProperty01$ & "\SAMAccountName_Postfix")
    	Dim LogFile as String = "E:\D1im\Logs\CN.LOG"
    	
    	If $Givenname$ <> $Givenname[o]$ Or $Surname$ <> $Surname[o]$ Then
    		If $Givenname$<>"" AndAlso $Surname$<>"" Then
    			CN = $Surname$ & " " & $Givenname$
    		ElseIf $Givenname$<>"" Then
    			CN = $Givenname$
    		ElseIf $Surname$<>"" Then
    			CN = $Surname$
    		Else
    			CN = $cn$
    		End If
    	Else
    		CN = $cn$
    	End If
    
    	Dim cnLen as Integer = Base.TableDef.Columns("CN").MaxLen
    	CN = VID_Left(CN, cnLen)
    	
    ' Add Postfix to privlidged Accounts.	
        If $IsPrivilegedAccount:Bool$ Then
    		Dim PostFixLength as Integer = Len(cnPostfix)
    		Dim PostFix as String = Right($cn$.ToString(), postFixLength)
    		' Check postfix agains last part of current CN
    		If Not PostFix.Equals(cnPostfix) Then  
    			CN = VID_Left(CN, cnLen + PostFixLength) & cnPostfix 
    		End If
        End If
    	
    	VID_Write2Log(LogFile, "Step 1: old - " & $cn$ & " New: " & $cn[o]$)
    	If $cn[o]$<>CN Or $UID_ADSContainer[o]$<>$UID_ADSContainer$ Then
    		i=1
    		CNFix = CN
    		If $UID_ADSContainer[o]$ <> "" Then
    			DNold = $FK(UID_ADSContainer[o]).DistinguishedName$
    		Else
    			DNold = $FK(UID_ADSDomain[o]).DistinguishedName$
    		End If
    		If $UID_ADSContainer$ <> "" Then
    			DNnew = $FK(UID_ADSContainer).DistinguishedName$
    		Else
    			DNnew = $FK(UID_ADSDomain).DistinguishedName$
    		End If
    
    		Domain = $UID_ADSDomain$
    		If DNold <> "" And DNold <> DNnew Then
    			wherePart = f.OrRelation( _
    							f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
    							f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
    								)
    		Else
    			wherePart =	f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
    		End If
    
    		Do While Connection.Exists(	"ADSAccount", _
    				f.AndRelation( _
    						f.UidComparison("UID_ADSAccount", $UID_ADSAccount$, CompareOperator.NotEqual), _
    						f.UidComparison("UID_ADSDomain", Domain), _
    						wherePart _
    							))
    			CN = VID_Left(CNfix, cnLen - (1 + CStr(i).Length)) & "_" & i
    			
    			If DNold <> "" And DNold <> DNnew Then
    				wherePart = f.OrRelation( _
    								f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
    								f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
    								)
    			Else
    				wherePart =	f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
    			End If
    			i=i+1
    		Loop
    	End If
    	Value = CN
    End If
    I am having a similar issue.  I had thought I have changed the logic to check if the (in my case) PostFix on the account is already there.  but this is creating an Infinite loop.   here is a copy of my additions to the code.  can anyone assist with what am missing.  or what I shoudl be checking against.

     

    If Not CBool(Variables("FULLSYNC")) AndAlso Not ($cn$).Contains(Chr(10)) Then
    	Dim CN, CNfix, DNold, DNnew,Domain, wherePart As String
    	Dim i As Integer
    	Dim f As ISqlFormatter = Connection.SqlFormatter
    	Dim CurrentEnvironment as String = Connection.GetConfigParm("Custom\CurrentEnvironment")
    	Dim cnPostfix as String = connection.GetConfigParm("Custom\" & CurrentEnvironment & "\TargetSystem\ADS\Accounts\PrivilegedAccount\" & $FK(UID_TSBAccountDef).CustomProperty01$ & "\SAMAccountName_Postfix")
    	Dim LogFile as String = "E:\D1im\Logs\CN.LOG"
    	
    	If $Givenname$ <> $Givenname[o]$ Or $Surname$ <> $Surname[o]$ Then
    		If $Givenname$<>"" AndAlso $Surname$<>"" Then
    			CN = $Surname$ & " " & $Givenname$
    		ElseIf $Givenname$<>"" Then
    			CN = $Givenname$
    		ElseIf $Surname$<>"" Then
    			CN = $Surname$
    		Else
    			CN = $cn$
    		End If
    	Else
    		CN = $cn$
    	End If
    
    	Dim cnLen as Integer = Base.TableDef.Columns("CN").MaxLen
    	CN = VID_Left(CN, cnLen)
    	
    ' Add Postfix to privlidged Accounts.	
    	If $IsPrivilegedAccount:Bool$ Then
    		Dim PostFixLength as Integer = Len(cnAppendix)
    		Dim PostFix as String = Right($cn$.ToString(), postFixLength)
    		' Check postfix agains last part of current CN
    		If Not PostFix.Equals(cnAppendix) Then  
    			CN = VID_Left(CN, cnLen + PostFixLength) & cnPostfix 
    		End If
        End If
    	
    	VID_Write2Log(LogFile, "Step 1: old - " & $cn$ & " New: " & $cn[o]$)
    	If $cn[o]$<>CN Or $UID_ADSContainer[o]$<>$UID_ADSContainer$ Then
    		i=1
    		CNFix = CN
    		If $UID_ADSContainer[o]$ <> "" Then
    			DNold = $FK(UID_ADSContainer[o]).DistinguishedName$
    		Else
    			DNold = $FK(UID_ADSDomain[o]).DistinguishedName$
    		End If
    		If $UID_ADSContainer$ <> "" Then
    			DNnew = $FK(UID_ADSContainer).DistinguishedName$
    		Else
    			DNnew = $FK(UID_ADSDomain).DistinguishedName$
    		End If
    
    		Domain = $UID_ADSDomain$
    		If DNold <> "" And DNold <> DNnew Then
    			wherePart = f.OrRelation( _
    							f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
    							f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
    								)
    		Else
    			wherePart =	f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
    		End If
    
    		Do While Connection.Exists(	"ADSAccount", _
    				f.AndRelation( _
    						f.UidComparison("UID_ADSAccount", $UID_ADSAccount$, CompareOperator.NotEqual), _
    						f.UidComparison("UID_ADSDomain", Domain), _
    						wherePart _
    							))
    			CN = VID_Left(CNfix, cnLen - (1 + CStr(i).Length)) & "_" & i
    			
    			If DNold <> "" And DNold <> DNnew Then
    				wherePart = f.OrRelation( _
    								f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String), _
    								f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNold), ValType.String) _
    								)
    			Else
    				wherePart =	f.Comparison("DistinguishedName", ADS_CreateDN("cn", CN, DNnew), ValType.String)
    			End If
    			i=i+1
    		Loop
    	End If
    	Value = CN
    End If