9 Replies Latest reply on Oct 25, 2011 11:21 PM by Tim Webb

    API to create Items without auto-update option

    Anton Nanchev

      Hi Guys,

      I’m working on EPDM add-in to automatically generate Items for all files passed specific (item-creation) workflow transition. Items have to be created without the auto-update option. The idea is to ensure that each Item will reference only one file version. When the same file passes “item-creation” transition again new Item has to be created referencing the new file-version.

      I’m using IEdmBatchItemGeneration2 interface, but I’m able to generate Items only with auto-update item to file reference. I thought that if I use EdmRefFlags.EdmRef_File during AddSelection2 method there wouldn’t be auto-update link, but the add-in generates an error.

       

      Can someone help me?

       

      Here is the rough code:

       

      Public Sub OnCmd(ByRef poCmd As EdmCmd, ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd

       

              'This routine is called when a hook triggers the add-in.

       

              On Error GoTo ErrHand

       

       

      runcode:

              Dim index, last As Object

              Dim VersionCounter As Integer

              Dim Value As Object

              Dim LoginName As Object

              Dim TransitionName, FileName, StateName, WorkflowName, FolderPath, Message As String

              Dim GenerateItems As Boolean = False

       

              index = LBound(ppoData)

              last = UBound(ppoData)

       

              Dim vault As EdmLib.EdmVault5

              vault = poCmd.mpoVault

       

              Dim Transition As EdmLib.IEdmTransition5

              Dim State As EdmLib.IEdmState6

              Dim Workflow As IEdmWorkflow6

              Dim file As EdmLib.IEdmFile5

              Dim folder As EdmLib.IEdmFolder5

              Message = "The following files have changed state:" & vbLf

       

              'create the item generation utility

              Dim batch As IEdmBatchItemGeneration2

              batch = vault.CreateUtility(EdmUtility.EdmUtil_BatchItemGeneration)

       

       

              'Process the files that are changing state.

              While index <= last

       

                  'Get transiton object

                  Transition = vault.GetObject(EdmObjectType.EdmObject_Transition, ppoData(index).mlObjectID3)

       

                  'Get state object

                  State = vault.GetObject(EdmObjectType.EdmObject_State, ppoData(index).mlLongData2)

       

                  'Get workflow object

                  Workflow = vault.GetObject(EdmObjectType.EdmObject_Workflow, State.WorkflowID)

       

                  'Get file object

                  file = vault.GetObject(EdmObjectType.EdmObject_File, ppoData(index).mlObjectID1)

       

                  'Get folder object

                  folder = vault.GetObject(EdmObjectType.EdmObject_Folder, ppoData(index).mlObjectID2)

       

                  'Get names

                  TransitionName = Transition.Name

                  FileName = file.Name

                  FolderPath = folder.LocalPath

                  StateName = ppoData(index).mbsStrData2

                  WorkflowName = Workflow.Name

       

                  'check if we are at the right transition to generate items

                  If TransitionName = "Change" And StateName = "State 2" Then

                      'we are going to generate at least one item

                      GenerateItems = True

       

                      'Add the file to the item generation utility

                      Dim emptyvars() As EdmVarVal

                      emptyvars = Nothing

                      batch.AddSelection2(vault, emptyvars, "", 0, file.ID, folder.ID, "", EdmRefFlags.EdmRef_File)

       

                      'write file info into the message string (temporary "debug" command)

                      Message = Message & "File: " & FolderPath & "\" & FileName & ", Transition name:" & TransitionName & ", Destination state: " & StateName & ", Workflow name: " & WorkflowName & vbLf

       

                      'Build the item tree.

                      Dim bDoGenerate As Boolean

       

                      bDoGenerate = batch.CreateTree(0, EdmItemGenerationFlags.Eigcf_Nothing)

                      If bDoGenerate = False Then Exit Sub

       

                  Else

       

                      Message = "You are not in the right transition"

       

                  End If

       

      GoOn:

                  'Process next file

                  index = index + 1

              End While

       

              MsgBox(Message, MsgBoxStyle.Information)

       

              If GenerateItems = False Then Exit Sub

       

              'Generate the items

              Dim retItems() As EdmGenItemInfo

              retItems = Nothing

              Dim bOpenExplorer As Boolean

              bOpenExplorer = False

              batch.GenerateItems(0, retItems, bOpenExplorer, Nothing)

       

              'Display status

              Dim msg As String

              msg = "Status:" + vbLf + vbLf

              Dim idx As Integer

              idx = LBound(retItems)

              While idx <= UBound(retItems)

                  msg = msg + "Item name: " + retItems(idx).mbsItemName + vbLf

                  msg = msg + "Alternate name: " + retItems(idx).mbsItemAlternativeName + vbLf

                  msg = msg + "Item database ID: " + CStr(retItems(idx).mlItemID) + vbLf

                  msg = msg + "Creation status: " + vault.GetErrorMessage(retItems(idx).mhResult) + vbLf + vbLf

                  idx = idx + 1

              End While

       

              MsgBox(msg)

       

       

              Exit Sub

       

       

      ErrHand:

              Dim ename As String

              Dim edesc As String

              vault.GetErrorString(Err.Number, ename, edesc)

              MsgBox(ename & vbLf & edesc)

       

          End Sub

          • Re: API to create Items without auto-update option
            Anton Nanchev

            According to the API reference guide EdmRefFlags options are:

            EdmRef_File - Item to file reference
            EdmRef_Item - Item to item reference
            EdmRef_Dynamic - Auto-update item to file reference
            EdmRef_Static - Attachment-type item to file reference

             

            The code from the post above works without problems with EdmRef_Dynamic  flag. I tried with EdmRef_File and EdmRef_Static.  Both times the error is the same: 0x5, Access is denied. The difference is that with EdmRef_Static the error is generated on GenerateItems method (the last step of IEdmBatchItemGeneration2) and with EdmRef_File on AddSelection2 method (the first step of IEdmBatchItemGeneration2).

             

            You can see the videos showing what’s happening. I’m attaching also the code.

              • Re: API to create Items without auto-update option
                Lee CS Young

                Are you logged in as a user that has permission to create items/files? Your code looks fine.

                • Re: API to create Items without auto-update option
                  Andries Koorzen

                  Hi everyone..

                   

                  @ Anton Not sure if you're still online these days.

                   

                  Did anyone ever manage to solve this problem? I seem to be running into a similar problem.

                   

                  When using

                   

                  batchItemGen.AddSelection2(vault, varVals, curnItem.ItemName)

                   

                  I get an error:

                   

                  ArgumentException: The parameter is incorrect.

                   

                  Unfortunately "The parameter is incorrect" is not very descriptive... what part is incorrect?

                   

                  Has anyone ever succesfully created items using the addSelection2 method? The samples from the API manual / Knowledge base also don't work...

                   

                  Thank you in advance

                    • Re: API to create Items without auto-update option
                      Anton Nanchev

                      Hi Andries,


                      We dropped using items at all on that particular project, but as I remember the code I've posted above worked without problems when the item-reference bit-flag of AddSelection2 was set to EdmRef_Dynamic.

                      As I see from your post you're passing to the method just the vault, the variables to write and the item name - try passing all parameters. The default value of EdmRefFlags (the last parameter of addselection2) is 0, but the bit-flags listed in the API manual are 1, 2, 4 and 8. I suppose that would’ve caused the error you're describing.


                        • Re: API to create Items without auto-update option
                          Andries Koorzen

                          Hi Anton.

                           

                          Thank you for the feedback..

                           

                          The code I use is as follows:

                           

                           

                           

                            Private Sub AddItemsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddItemsButton.Click

                           

                           

                           

                           

                                  Dim vault As IEdmVault5 = EdmVaultSingleton.Instance

                           

                           

                                  If Not vault.IsLoggedIn Then

                                      vault.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32)

                                  End If

                           

                           

                                  'Create the batch interface

                                  Dim batch As IEdmBatchItemGeneration2

                           

                           

                                  batch = vault.CreateUtility(EdmUtility.EdmUtil_BatchItemGeneration)

                           

                           

                                  'Append the first item to the batch

                                  Dim vars(0) As EdmVarVal

                                  vars(0).moVarIDorName = "Description"

                                  vars(0).moValue = "My first item"

                                  vars(0).mlEdmVarValFlags = 0

                                  batch.AddSelection2(vault, vars, "TheFirstItem", , , , , EdmRefFlags.EdmRef_Static)

                           

                           

                                  'Append the second (auto-named) item to the batch.

                                  Dim emptyvars() As EdmVarVal

                                  emptyvars = Nothing

                                  batch.AddSelection2(vault, emptyvars, "NoItemName", , , , , EdmRefFlags.EdmRef_Dynamic)

                           

                           

                                  'Build the item tree.

                                  If (batch.CreateTree(Me.Handle.ToInt32, EdmItemGenerationFlags.Eigcf_Nothing) = False) Then Exit Sub

                           

                           

                                  'Generate the items

                                  Dim retItems() As EdmGenItemInfo

                                  retItems = Nothing

                                  Dim bOpenExplorer As Boolean

                                  bOpenExplorer = False

                                  batch.GenerateItems(Me.Handle.ToInt32, retItems, bOpenExplorer, Nothing)

                           

                           

                                  'Display status

                                  Dim msg As String

                                  msg = "Status:" + vbLf + vbLf

                                  Dim idx As Integer

                                  idx = LBound(retItems)

                                  While idx <= UBound(retItems)

                                      msg = msg + "Item name: " + retItems(idx).mbsItemName + vbLf

                                      msg = msg + "Alternate name: " + retItems(idx).mbsItemAlternativeName + vbLf

                                      msg = msg + "Item database ID: " + CStr(retItems(idx).mlItemID) + vbLf

                                      msg = msg + "Creation status: " + vault.GetErrorMessage(retItems(idx).mhResult) + vbLf + vbLf

                                      idx = idx + 1

                                  End While

                           

                           

                                  MsgBox(msg)

                           

                           

                           

                          This code comes from one of the samples in the API help sections. It gives me an error as well. Depending on the code I used, I get different errors. I have actually tried a compiled version from the Knowledge base which also gives the same error. I'm starting to suspect that it might have to do with my installation.

                           

                          I've decided to upgrade to EPDM 2011 SP5.0, just finished downloading that. If that doesn' work, I'll run a test setup on EPDM 2012 SP0.

                           

                          If that doesn't work... I'm giving up my job and will become an ice cream salesman.

                           

                          *