AddValueListItem Method does not commit the item to the list.

Hi,

Trying to add an item to a value list using the AddValueListItem Method using this code in a workflow script (grabbed from an example Craig created a while back)

     Dim objValueListItem: Set objValueListItem = CreateObject("MFilesAPI.ValueListItem")
     objValueListItem.Name = sItemName
     'objValueListItem.ValueListID = iValueListId
     Vault.ValueListItemOperations.AddValueListItem iValueListId, objValueListItem, True
     Err.Raise mfscriptcancel, objValueListItem.ID &", name "& sItemName  &", list "& iValueListID

 The code always returns 0 as objValueListItem.ID, the other values are as expected.

When checking the content of the valuelist after running the code, no new items appear. However, if you manually add a new item this new item will skip a number of ID numbers equivalent to the number of times the code has been run since last. It looks as if the code reserves an ID but never commits the new item.

What can I do to make sure the code commits the new item?
The code runs in a function that will be called multiple times in a "for each" loop.
I need to pick up the new IDs in a collection of lookups that can be committed as property value in a multiselect lookup at the end of the script.

Thanks for any hints, Karl

Parents
  • The AddValueListItem method returns the value list item:

         Dim objValueListItem: Set objValueListItem = CreateObject("MFilesAPI.ValueListItem")
         objValueListItem.Name = sItemName
         Set objValueListItem = Vault.ValueListItemOperations.AddValueListItem(iValueListId, objValueListItem, True)
         Err.Raise mfscriptcancel, objValueListItem.ID &", name "& sItemName  &", list "& iValueListID
         

    That should at least show an ID now.

    Note, though, that the err.raise will roll back the transaction, so the item would only be committed if this code ran with no exceptions being thrown (or messages shown, in this case).

  • Thanks Craig,

    Your change to the code made the difference, now an ID is returned. And yes, I had for a moment forgotten that things won't get committed when you break off the script. Sorry about that mistake. I bit weird though that the ID reserved for the new item remains in the database only as an invisible item with no name. But there is no harm in that.

    Enjoy your vacation.

Reply Children
No Data