UpdateItem error

UpdateItem error

sleeping_dragon69KJN
Explorer Explorer
387 Views
2 Replies
Message 1 of 3

UpdateItem error

sleeping_dragon69KJN
Explorer
Explorer

We are using Web Services API - Vault Professional 2025.3 to add and update an item with the following code: 

    Public Function AddItem(vf As VaultedFile, catID As Long) As Item
        Dim item As Item = wsm.ItemService.AddItemRevision(catID)
        item = wsm.ItemService.EditItems(New Long() {item.RevId})(0)

        If item.Locked = False Then
            ' set the needed information
            item.Title = vf.WorkFile.Name
            item.Detail = vf.WorkFile.Name
            ' save the item revision
            Try
                wsm.ItemService.UpdateAndCommitItems(New Item() {item})
            Catch ex As Exception
                Dim eh As New ErrorHandler(ex, "Error creating Item:", vf)
                eh.QuietlyHandleIt()
            End Try
        End If

        Return item
    End Function

 It works fine on a clean test vault, and even my home production vault.  However on a certain server with a certain vault it fails everytime, because the SP (watched with SQL Profiler) received IMItemNumber=default instead of a value like = "00000023".  This happens exactly on the line UpdateAndCommitItems(), which returns SOAP error 1306.  I checked EVERY single line of custom configuration, I removed (since we have a prod and test version that both show the error) every single piece of behavior customization that could effect items (LifeCycles, Revisions, Categories, Rule, Naming, Property Mappings).  Problem persists in these specific vaults.  I thought I could outsmart the issue by copying a bad vault's configuration to a clean vault, but the problem did NOT reproduce itself after that. It also doesn't matter the file I use.  All files fail or All files pass depending on the vault database i'm logged into (even a good database on the same ADMS server with the bad ones).

 

Production 3 server replicated ADMS:

Bad Vaults:

  • Prod - One old database (migrated from as far back as 2018),
  • Prod Test - one new database (pulled config from migrated one, after installed clean, and then tested upon).

Good Vaults:

  • Clean - One new database (pulled no configs)

Home based simple ADMS:

Good Vaults:

  • Personal - One old database (migrated from 2020),
  • Test - one new database (used config from bad database above)

Below is the profiler's capture of the command to UpdateItem that caused the error.  Notice the @IMItemNumber=default.  This is the behavior causing the error.  I can't find what is making it do that.  

 

exec UpdateItem @IITID=7483849,@IITDetail=N'H7TEST-2101-01E06.ipt',@IITUnits=N'Each',@ITComment=N'',@IRID=1680587,@IMID=7483848,@IMItemNumber=default,@IMTitle=N'TEST.ipt',@updateUserID=10119,@loginSession='4BAEBA4B-9EC9-42FE-A40A-893628B5084F',@UoMID=1,@BOMStructID=1,@commitChanges=1,@createDate='2025-06-09 05:10:44.400'

 

I'm stumped, any help would be nice.

 

Thank you,

 

jvj

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Accepted solutions (1)
388 Views
2 Replies
Replies (2)
Message 2 of 3

Nick_Hall
Collaborator
Collaborator
Accepted solution

Hi jvj

 

It doesn't look like you are providing an item number, so maybe the difference between the vaults is that the one that is failing doesn't know which number/scheme to use

 

It may or may not help, but this is the code I use to create an item using the API. It's in PowerShell, but you should get the idea.

Inputs are 

  • $itemNumber - The item number
  • $catId - Category ID for the item
  • $numSchemeId - Numbering Scheme ID
  • $fileDescription = Description
  • $fileTitle = Title
Write-Host "Creating Item [$($itemNumber)]"
[Autodesk.Connectivity.WebServices.Item]$vaultItem = $vault.ItemService.AddItemRevision($catId)
[Autodesk.Connectivity.WebServices.StringArray]$stringArray = (New-Object -TypeName Autodesk.Connectivity.WebServices.StringArray)
$stringArray.Items = @($itemNumber)
[Autodesk.Connectivity.WebServices.StringArray[]]$fieldInputs = @($stringArray)
[Autodesk.Connectivity.WebServices.ProductRestric[]]$restrictions = $null
[Autodesk.Connectivity.WebServices.ItemNum[]]$vaultItemNum = $vault.ItemService.AddItemNumbers(@($vaultItem.MasterId),@($numSchemeId),$fieldInputs,[ref]$restrictions)
$vault.ItemService.CommitItemNumbers(@($vaultItemNum[0].ItemMasterId),@($vaultItemNum[0].ItemNum1))
$vaultItem.ItemNum = $vaultItemNum[0].ItemNum1
$vaultItem.Detail = $fileDescription
$vaultItem.Title = $fileTitle
$vault.ItemService.UpdateAndCommitItems(@($vaultItem))

 

Hope it helps

Nick

Message 3 of 3

sleeping_dragon69KJN
Explorer
Explorer

 I'm not sure how much of a solution this is, but I certainly adopted it.  I like the whole create the itemNumber directly thing.

for the hungry at heart, here is my updated function (untested really):

Public Function AddItem(vf As VaultedFile, catID As Long, numSchemeId As Long) As Item
    Dim item As Item = wsm.ItemService.AddItemRevision(catID)
    item = wsm.ItemService.EditItems(New Long() {item.RevId})(0)
    'assign file name without extension to the ItemNumber
    Dim stringArray As New StringArray()
    stringArray.Items = New String() {SIO.Path.GetFileNameWithoutExtension(vf.WorkFilePath)}
    Dim fieldInputs() As StringArray = {stringArray}
    ' Add Item Numbers
    Dim restrictions() As ProductRestric = Nothing
    Dim vaultItemNum() As ItemNum = wsm.ItemService.AddItemNumbers(New Long() {item.MasterId}, New Long() {numSchemeId}, fieldInputs, restrictions)
    ' Commit Item Numbers
    wsm.ItemService.CommitItemNumbers(New Long() {vaultItemNum(0).ItemMasterId}, New String() {vaultItemNum(0).ItemNum1})

    item.ItemNum = vaultItemNum(0).ItemNum1
    ' set the needed information
    item.Title = vf.WorkFile.Name
    item.Detail = vf.WorkFile.Name
    ' save the item revision
    Try
        wsm.ItemService.UpdateAndCommitItems(New Item() {item})
    Catch ex As Exception
        Dim eh As New ErrorHandler(ex, "Error creating Item:", vf)
        eh.QuietlyHandleIt()
    End Try

    Return item
End Function

  Reminds me of when I had my first lousy automatic transmission that wouldn't up shift, so I changed over to stick shift just so I could have all the control. 

 

Thank you,

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes