HI, I have a document with a field that accepts multiple values, and then these documents are categorized in a view using the multi-value field as the category (key).
For example.
FieldName =SerialNumbers
FieldValue =AB1234, AB1222
View is sorted and categorized using the Field SerialNumbers.
The view displays ‘two’ records
AB1234
AB1222
however, as we know, this is the same document.
When looking up this view using GetDocumentByKey I get a type mismatch when it reaches that multi-valued document.
Using the debugger I can tell why but I can’t figure out what the work around is (if any).
Below is a snippet of the code. Basically the problem hits when it reaches this line:
newdoc.ColumnValues( column.Position - 1 ) = _
doc.DocUNID(0) & doc.IPEquivalent(i-1)) Then
because newdoc.ColumnValues(0) actually has an array of values (2 in this case) and therefore give me a “Type Mismatch” error. I tried writing newdoc.ColumnValues(0)(i) but it says illegal use of parenthesis!
Is there a way around this?
…
Set db = session.CurrentDatabase
Set view = db.GetView ("(qryValidateDocIDIP)")
Forall c In view.Columns
If ( c.IsSorted And c.IsCategory ) Then
Set column = c
Exit Forall
End If
End Forall
Set newdoc = view.GetDocumentByKey( doc.DocUNID(0) & doc.IPEquivalent(i-1) )
Do While Not ( newdoc Is Nothing)
If ( newdoc.ColumnValues( column.Position - 1 ) = _
doc.DocUNID(0) & doc.IPEquivalent(i-1)) Then .....
HI thomas, the problem is not on that line, the error hits on this one:
If ( newdoc.ColumnValues(0) = doc.DocUNID(0) & doc.IPEquivalent(i-1)) Then
they are all of type TEXT, its the fact that ColumnValues(0) also has an array of values (this is what causes the Type Mismatch).
Usually a categorized column witll have only one value, but because my field that I am categorizing by is a multi-value field it may have 2 or more values and therefore it gets stuck.
Hi Bill, thanks for the response. By using a forall you’ve pointed me in the right direction and I’ve made some progress but I’m still experiencing some issues. basically, i get a type mismatch now when the document’s key does NOT have more than one key. Is there a way to find out the count of something before doing a forall, in other words, if count < 1 then do this else Forall j In blah etc…
here is my revised code:
Set newdoc = view.GetDocumentByKey( doc.DocUNID(0) & doc.IPEquivalent(i-1) )
Do While Not ( newdoc Is Nothing)
checkIP = doc.DocUNID(0) & doc.IPEquivalent(i-1)
categorykey = newdoc.ColumnValues(0)
count = 0
Forall j In categorykey '(this is where i get TYPE MISMTACH if the document matched has ONLY 1 KEY)...find out how many key values in the match
count = count +1
End Forall
If count > 1 Then 'if the count is greatet then 1 than use the forall technique without exiting the do if this first match is not satisfied
Forall j In categorykey
If j = checkIP Then
flagIP = "OK"
Exit Do
End If
End Forall
Else 'if the count is 1 then use std method of checking document exiting the do if it is not a matching document
If newdoc.ColumnValues(0) = checkIP Then
flagIP = "OK"
Exit Do
Else
Exit Do
End If
End If
Set newdoc = view.GetNextDocument( newdoc )
Loop
Hey Bill, I resolved the issue by being able to test if column.values contained an array or not by using the IsArray function. If its true i proceeded with the forall like you suggested, if it was false i check it as usual.