AnsweredAssumed Answered

API to create Items without auto-update option

Question asked by Anton Nanchev on Jul 22, 2010
Latest reply on Oct 25, 2011 by Tim Webb

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

Outcomes