19. April 2010 09:31
Function getGUID(ByVal entity As String, ByVal field As String, ByVal searchword As String) As Guid
If entity = "account" Then
Dim queryAccount As New QueryByAttribute()
queryAccount.ColumnSet = New AllColumns()
queryAccount.EntityName = EntityName.account.ToString()
queryAccount.Attributes = New String() {field}
queryAccount.Values = New String() {searchword}
Dim retrievedAccount As BusinessEntityCollection = service.RetrieveMultiple(queryAccount)
Try
Dim account As account = CType(retrievedAccount.BusinessEntities(0), account)
Dim idAccount As Guid = account.accountid.Value
Return idAccount
Catch ex As Exception
protoWrite(ex.ToString)
protoWrite("KEIN SUCHERGEBNIS")
Console.WriteLine(ex)
Console.WriteLine("KEIN SUCHERGEBNIS")
End Try
End If
If entity = "contact" Then
Dim queryContact As New QueryByAttribute()
queryContact.ColumnSet = New AllColumns()
queryContact.EntityName = EntityName.contact.ToString()
queryContact.Attributes = New String() {field}
queryContact.Values = New String() {searchword}
Try
Dim retrievedContact As BusinessEntityCollection = service.RetrieveMultiple(queryContact)
Dim contact As contact = CType(retrievedContact.BusinessEntities(0), contact)
Dim idContact As Guid = contact.contactid.Value
Return idContact
Catch ex As Exception
protoWrite(ex.ToString)
protoWrite("KEIN SUCHERGEBNIS")
Console.WriteLine(ex)
Console.WriteLine("KEIN SUCHERGEBNIS")
End Try
End If
19. April 2010 13:35