SearchConditions: Find id from name

Build 1501 on 14/Nov/2017  This topic last edited on: 21/Mar/2016, at 18:44

Version 2.0 or newer

    Dim variantTypeId As Integer = DBDesc.InvalidId

    Dim sc As SearchConditions = New SearchConditions(Schema.Class.variantTypeObj.ObjectTypeName)

    sc.List = New Common.Search.Node.Condition(New Common.Search.Node.Attribute("variantType.name"), OpCode.Equal, variantTypeName)

    Dim variantTypes As List(Of IdName) = login.ListObjs(New ExtSearchConditions(sc, login), False, SpikedHandling.Exclude)

    If Not variantTypes Is Nothing AndAlso variantTypes.Count > 0 Then

      variantTypeId = variantTypes(0).Id

    End If

    If variantTypeId = DBDesc.InvalidId Then

      Return 'cannot find a variantType with the input name

    End If

Version 1.6 or older

'find the id of the variantType

Dim variantTypeId As Integer = DBDesc.InvalidId

Dim sc As SearchConditions = New SearchConditions(Schema.Class.variantTypeObj.ObjectTypeName)

sc.List = New Common.Search.Node.Condition(New Common.Search.Node.Attribute("variantType.name"), OpCode.Equal, variantTypeName)

Dim variantTypes As List(Of IdName) = login.ListObjs(sc, False)

If Not variantTypes Is Nothing AndAlso variantTypes.Count > 0 Then

  variantTypeId = variantTypes(0).Id

End If

If variantTypeId = DBDesc.InvalidId Then

  Return 'cannot find a variantType with the input name

End If