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

Problem with retrieving UNSRootB object

When I invoked code:

If Session.Source.TryGet( Query.From("UNSRootB") _ 
                               .Where(f.UidComparison("UID_UNSRootB", UID_UNSRootB, CompareOperator.Equal)) _
                               .SelectNonLobs, UNSRootB )
    ...
End If

TryGet results with False (object could not be found).

On the other hand when I execute SQL query:

SELECT * FROM UNSRootB WHERE UID_UNSRootB = '<UID_UNSRootB>'

it returns one row.

IDM ver. 7.1.2

  • Where does this code gets executed and which credentials/authentication-module was used?
  • In Designer > Test script with 'Use transaction' disable:

    Public Function TSB_UNSRootB_Get(ByVal Ident_UNSRoot As String) As IEntity
    
        If String.IsNullOrEmpty(Ident_UNSRoot) Then
    		Throw New ArgumentNullException("Ident_UNSRoot")
    	End If
    
    	Dim f As ISqlFormatter = Connection.SqlFormatter
    	Dim UID_UNSRootB As String = Ident_UNSRoot
    	Dim UNSRootB As IEntity = Nothing
    	
    	If Not StringIsUID(Ident_UNSRoot) Then
       	    UID_UNSRootB = Connection.GetSingleProperty("UNSRootB", "UID_UNSRootB", f.Comparison("Ident_UNSRoot", Ident_UNSRoot, ValType.String, CompareOperator.Equal))
    	End If
    	
    	If Session.Source.TryGet( Query.From("UNSRootB") _
    		                           .Where(f.Comparison("UID_UNSRootB", UID_UNSRootB, ValType.String, CompareOperator.Equal)) _
    						           .SelectNonLobs, UNSRootB )
    		Return UNSRootB
        Else
    		Throw New Exception(#LD("Could not determine target system object")#)
        End If
    
    End Function
    
    Public Function StringIsUID(ByVal UID As String) As Boolean
    		
    	If String.IsNullOrEmpty(UID) Then
    		Return False
    	End If
    		
    	Dim regex = New RegularExpressions.Regex("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$", RegularExpressions.RegexOptions.Compiled)
    	Return regex.IsMatch(UID)
    		
    End Function

    As a parameter You can use Ident_UNSRoot or UID_UNSRootB.

    When Ident_UNSRoot is used the propert object is returned.

    When UID_UNSRootB is used then I got exception.

  • Your script works for me in either case, using an Ident_UNSRoot or an UID_UNSRootB.

    The only suggestion I have is to replace the f.Comparison method with an f.UidComparison method. It might be a rare case, but the generated where-clauses are different.

    Your comparison method generates a where-clause like

    UID_UNSRootB = N'<UID_UNSRootB>'

    while UidComparison generates

    UID_UNSRootB = '<UID_UNSRootB>'

    In version 7 and above, all UIDs are Non-Unicode so the second where clause is the correct one.

    Bonus:

    .Where(f.UidComparison("UID_UNSRootB", UID_UNSRootB) ) _

    is shorter as well :-)

  • In my environment none of those methods (f.Comparision or f.UidComparison) won't work for UID_UNSRootB. Weird thing. I've no problems with other tables.
  • I suggest that you debug your script in the System Debugger using single-step debugging, check the generated where-clause from the SQL Formatter and test this with SQL Server Management Studio. Does it bring any result then?