- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm fairly new to programming, so bear with me...
I'm trying to to make a section of code that will find a file by searching for an assembly part number. Once the file is found, I want to return all the associated file names (the sub-assemblies and parts) like the "uses" tool in vault. I'm trying to use GetFileAssociationLites to find the related file IDs and then GetFilesByIds to return an array of all the files which I can then get the names of, but something is wrong.
It is giving me an error at the GetFilesByIds line, which I think is related to the output from GetFileAssociationLites, but I can't figure out the issue. Everything else seems to be working.
Any help is really appreciated... thanks
'part number search term (hardcoded for example)
Dim searchterm As String
searchterm = "5-AIIDRI12TA-KT87SB"
'set up search
Dim filePropDefs As PropDef() = connection.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
Dim projectPropDef As PropDef = filePropDefs.[Single](Function(n) n.SysName = "PartNumber")
Dim condition As New SrchCond() With {.PropDefId = projectPropDef.Id, .PropTyp = PropertySearchType.SingleProperty, .SrchOper = 3, .SrchRule = SearchRuleType.Must, .SrchTxt = searchterm}
Dim bookmark As String = String.Empty
Dim status As SrchStatus = Nothing
'do the search and return the file(s) with the matching part number
Dim files As File() = connection.WebServiceManager.DocumentService.FindFilesBySearchConditions(New SrchCond() {condition}, Nothing, Nothing, True, True, bookmark, status)
'setup file relationship settings (for use in the loop below)
Dim myFileRelationshipSettings As VDF.Vault.Settings.FileRelationshipGatheringSettings
myFileRelationshipSettings = New VDF.Vault.Settings.FileRelationshipGatheringSettings
myFileRelationshipSettings.IncludeAttachments = False
myFileRelationshipSettings.IncludeChildren = True
myFileRelationshipSettings.IncludeParents = True
myFileRelationshipSettings.IncludeRelatedDocumentation = False
'go through each file found with the search term
If files IsNot Nothing AndAlso files.Any() Then
For Each file As File In files
'get the file ID from the file
Dim fileid As Long
fileid = file.Id
'use this file ID to find the associated file IDs and store in an array
Dim relatedfileids As Array
relatedfileids = connection.FileManager.GetFileAssociationLites(New Long() {fileid}, myFileRelationshipSettings)
'use the related file IDs to find each associated file and store in an array
Dim relatedfiles As Array
relatedfiles = connection.WebServiceManager.DocumentService.GetFilesByIds(relatedfileids) '********** This line is giving me the error **********
'(testing only) send each associated file name to a message box to check what's going on
Dim i As Long
For i = 0 To UBound(relatedfiles)
MsgBox(relatedfiles(i).name)
Next
Next
End IfSolved! Go to Solution.