Set property value at lifecycle transition

Set property value at lifecycle transition

Anonymous
Not applicable
1,412 Views
4 Replies
Message 1 of 5

Set property value at lifecycle transition

Anonymous
Not applicable

I would like to set the value of a property (in this case Design Phase to 30%, etc) at the transition of a lifecycle state. I believe a custom job could be written to accomplish this. How would I go about it?

0 Likes
1,413 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Hi Jeff,

 

I have done something similar, my code adds the user details and date to a UDP on a lifecycle transition, and a few other things.

 

I'm all self taught when it comes to coding, so this may not be the most efficient way, hopefully you will find it useful. 

 

 

    Public Class EventHandlers
        Implements IWebServiceExtension
        Dim Processing As Boolean
        Public Sub OnLoad() Implements IWebServiceExtension.OnLoad

            AddHandler DocumentService.AddFileEvents.Post, AddressOf AddCreatorAndDateOnAddFile
            AddHandler DocumentService.CheckoutFileEvents.Pre, AddressOf AddCreatorAndDateOnCheckout
            AddHandler DocumentServiceExtensions.UpdateFileLifecycleStateEvents.Post, AddressOf Delete_property_values
            AddHandler DocumentServiceExtensions.UpdateFileLifecycleStateEvents.Pre, AddressOf Add_property_values

        End Sub

        Private Sub AddCreatorAndDateOnAddFile(ByVal sender As Object, ByVal e As AddFileCommandEventArgs)

            'establish a connection to vault with current users details
            Dim results As VDF.Vault.Results.LogInResult
            Dim OrgName As String = System.Environment.UserName
            If e.FileName.EndsWith(".dwf") Or e.FileName.EndsWith(".DWF") Then
                Return
            End If
            results = VDF.Vault.Library.ConnectionManager.LogIn("xxxxx", "xxxxx", "", "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)
            If Not results.Success Then
                Return
            End If
            Dim m_conn As Connection = results.Connection

            'get file id
            Dim FileNme As String = Right(e.FileName, Len(e.FileName) - InStrRev(e.FileName, "\"))
            Dim IndFileId As Long
            Dim AllFilesInFolder As File() = m_conn.WebServiceManager.DocumentService.GetLatestFilesByFolderId(e.FolderId, True)
            For Each Sepfile As File In AllFilesInFolder
                If Sepfile.Name = FileNme Then
                    IndFileId = Sepfile.Id
                    Exit For
                End If
            Next Sepfile

            'Get orginator name
            OrgName = Right(OrgName, Len(OrgName) - InStrRev(OrgName, "\")) 'remove domain
            OrgName = Replace(OrgName, ".", " ") 'replace the period with a space
            OrgName = StrConv(OrgName, VbStrConv.Uppercase) 'convert to uppercase

            'Get orginal create date
            Dim OrgDateDte As Date = Now
            Dim OrgDate As String = OrgDateDte.ToShortDateString

            'change properties
            'create dictionary
            Dim myPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"5716a6eb-53c9-4fb3-b13d-205edfc714c4", "505a747a-d62a-4a8b-bff9-2e149daafce2"})
            Dim propsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            Dim OrgNameObj As Object = OrgName
            Dim OrgDateObj As Object = OrgDate

            propsDict.Add(myPropDefArray(0), OrgNameObj)
            propsDict.Add(myPropDefArray(1), OrgDateObj)

            'Load ExplorerUtil
            Dim VaultExplorerUtil As IExplorerUtil = ExplorerLoader.LoadExplorerUtil(m_conn.Server, m_conn.Vault, m_conn.UserID, m_conn.Ticket)

            'change properties
            Dim indfile As File = m_conn.WebServiceManager.DocumentService.GetFileById(IndFileId)
            Processing = True
            VaultExplorerUtil.UpdateFileProperties(indfile, propsDict)
            Processing = False

            'Close ExplorerUtil
            VaultExplorerUtil = Nothing

            'loggout of the vault server
            VDF.Vault.Library.ConnectionManager.LogOut(m_conn)

        End Sub

        Private Sub AddCreatorAndDateOnCheckout(ByVal sender As Object, ByVal e As CheckoutFileCommandEventArgs)

            'exit if existing checkout event is running, if not log this change event
            If Processing = True Then
                Return
            End If

            'establish a connection to vault with current users details
            Dim results As VDF.Vault.Results.LogInResult
            results = VDF.Vault.Library.ConnectionManager.LogIn("xxxxx", "xxxxx", "", "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)
            If Not results.Success Then
                Return
            End If
            Dim m_conn As Connection = results.Connection

            'exit if dwf
            Dim indfile As File = m_conn.WebServiceManager.DocumentService.GetFileById(e.FileId)
            If indfile.Name.EndsWith(".dwf") Or indfile.Name.EndsWith(".DWF") Then
                'loggout of the vault server
                VDF.Vault.Library.ConnectionManager.LogOut(m_conn)
                Return
            End If

            'get properties
            Dim props As PropDef() = m_conn.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FILE")
            Dim PropIdArray(3) As Long
            For Each OrgProp As PropDef In props
                If OrgProp.SysName = "Originator" Then PropIdArray(0) = OrgProp.Id
                If OrgProp.SysName = "OrigCreateDate" Then PropIdArray(1) = OrgProp.Id
                If OrgProp.SysName = "5716a6eb-53c9-4fb3-b13d-205edfc714c4" Then PropIdArray(2) = OrgProp.Id
                If OrgProp.SysName = "505a747a-d62a-4a8b-bff9-2e149daafce2" Then PropIdArray(3) = OrgProp.Id
            Next OrgProp
            Dim PropInstArray As PropInst() = m_conn.WebServiceManager.PropertyService.GetProperties("FILE", New Long() {e.FileId}, PropIdArray)

            'Get orginator name
            Dim OrgName As String = PropInstArray(0).Val
            OrgName = Right(OrgName, Len(OrgName) - InStrRev(OrgName, "\")) 'remove domain
            OrgName = Replace(OrgName, ".", " ") 'replace the period with a space
            OrgName = StrConv(OrgName, VbStrConv.Uppercase) 'convert to uppercase

            'Get orginal create date
            Dim OrgDateDte As Date = PropInstArray(1).Val
            Dim OrgDate As String = OrgDateDte.ToShortDateString

            'Get orginator name (text)
            Dim OrgTextName As String
            OrgTextName = PropInstArray(3).Val

            'Get orginal create date (text)
            Dim OrgDateText As String
            OrgDateText = PropInstArray(2).Val

            'change properties
            'create dictionary
            If OrgName <> OrgTextName Or OrgDate <> OrgDateText Then
                Dim myPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"5716a6eb-53c9-4fb3-b13d-205edfc714c4", "505a747a-d62a-4a8b-bff9-2e149daafce2"})
                Dim propsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
                Dim OrgNameObj As Object = OrgName
                Dim OrgDateObj As Object = OrgDate

                propsDict.Add(myPropDefArray(0), OrgNameObj)
                propsDict.Add(myPropDefArray(1), OrgDateObj)

                'Load ExplorerUtil
                Dim VaultExplorerUtil As IExplorerUtil = ExplorerLoader.LoadExplorerUtil(m_conn.Server, m_conn.Vault, m_conn.UserID, m_conn.Ticket)

                'change properties
                Processing = True
                VaultExplorerUtil.UpdateFileProperties(indfile, propsDict)
                Processing = False

                'Close ExplorerUtil
                VaultExplorerUtil = Nothing

            End If

            'loggout of the vault server
            VDF.Vault.Library.ConnectionManager.LogOut(m_conn)

        End Sub

        Private Sub Delete_property_values(ByVal sender As Object, ByVal e As UpdateFileLifeCycleStateCommandEventArgs)

            'Get a list of the master ids for files that are transitioning to the "work in progress" state of the "TTABWIP" and "ABMAIN" lifecycle.
            Dim WIPFileIdList(-1) As Long
            Dim ABMFileIdList(-1) As Long
            For i As Byte = LBound(e.FileMasterIds) To UBound(e.FileMasterIds)
                If e.ToStateIds(i) = 29 Then
                    ReDim Preserve WIPFileIdList(UBound(WIPFileIdList) + 1)
                    WIPFileIdList(UBound(WIPFileIdList)) = e.FileMasterIds(i)
                End If
                If e.ToStateIds(i) = 47 Then
                    ReDim Preserve ABMFileIdList(UBound(ABMFileIdList) + 1)
                    ABMFileIdList(UBound(ABMFileIdList)) = e.FileMasterIds(i)
                End If
            Next i
            If UBound(WIPFileIdList) = -1 And UBound(ABMFileIdList) = -1 Then
                Return
            End If

            'establish a connection to vault with current users details
            Dim results As VDF.Vault.Results.LogInResult
            results = VDF.Vault.Library.ConnectionManager.LogIn("xxxxx", "xxxxx", "", "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)
            If Not results.Success Then
                Return
            End If
            Dim m_conn As Connection = results.Connection

            'get list of latest files from the list of master ids
            Dim WIPfilelist As File()
            Dim ABMfilelist As File()
            If UBound(WIPFileIdList) <> -1 Then
                WIPfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(WIPFileIdList)
            End If
            If UBound(ABMFileIdList) <> -1 Then
                ABMfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(ABMFileIdList)
            End If

            'Make dictionary
            Dim updateValueObj As Object = Nothing
            Dim Change_Note_prop As String = "Change Note-{b98cc773-ce0a-44a0-80a7-27a951bbb202}"
            Dim Approval_Date_prop As String = "Approval date-{576aa6d6-6e6a-411c-9575-d35ab5a5ba03}"
            Dim Approval_Date_Drawing_prop As String = "Approval Date Drawing-{1d7fa910-e347-4e8f-87ae-45c1412ba4e0}"
            Dim Approved_by_prop As String = "Approved by-{6f303c25-1e20-4f90-9461-d43498c65f79}"
            Dim Checked_By_prop As String = "CheckedBy"
            Dim Checked_date_prop As String = "Checked date-{0172e3de-5a6e-47c7-b68d-3fd057def917}"
            Dim Checked_date_text_prop As String = "50a26fa2-c547-4a82-aaa1-7960da2ae827"
            Dim Issued_By_prop As String = "Issued By-{6e2f891e-904a-425f-9878-db0278b4a458}"
            Dim Issued_Date_prop As String = "Issued Date-{a53a81dc-0b1f-42aa-83f9-a98bc811a5e1}"
            Dim Issued_Date_text_prop As String = "3be98b49-848b-4559-867f-632a4ce576eb"
            Dim Change_Desc_Prop As String = "f1f74cf9-2402-4d26-945e-6a4135d20775"
            Dim Zone_Prop As String = "b3bd0cd2-1a91-4ec1-aaed-6d2831e9b4b0"
            Dim Mass_Prop As String = "435a1237-bd0e-426a-87f6-f67c078e8170"
            Dim Document_Status_prop As String = "84cc39eb-05d1-4Db1-8d66-3Fb9e0f03df6"
            Dim WIPpropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            Dim ABMpropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            'make a dictinary of properties that are going to change for the WIP lifecycle
            If UBound(WIPFileIdList) <> -1 Then
                Dim WIPPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {Approval_Date_prop, Approval_Date_Drawing_prop, Approved_by_prop, Checked_By_prop, Checked_date_prop, Checked_date_text_prop, Issued_By_prop, Issued_Date_prop,
                Issued_Date_text_prop, Document_Status_prop})
                For i = LBound(WIPPropDefArray) To UBound(WIPPropDefArray) - 1
                    WIPpropsDict.Add(WIPPropDefArray(i), updateValueObj)
                Next i
                Dim WIPDocStatus As Object = "CONCEPT DEVELOPMENT"
                WIPpropsDict.Add(WIPPropDefArray(UBound(WIPPropDefArray)), WIPDocStatus)
            End If

            'make a dictinary of properties that are going to change for the ABMAIN lifecycle
            If UBound(ABMFileIdList) <> -1 Then
                Dim ABMPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {Change_Note_prop, Approval_Date_prop, Approval_Date_Drawing_prop, Approved_by_prop, Checked_By_prop, Checked_date_prop, Checked_date_text_prop, Issued_By_prop, Issued_Date_prop,
                Issued_Date_text_prop, Change_Desc_Prop, Zone_Prop, Mass_Prop, Document_Status_prop})
                For i = LBound(ABMPropDefArray) To UBound(ABMPropDefArray) - 1
                    ABMpropsDict.Add(ABMPropDefArray(i), updateValueObj)
                Next i
                Dim ABMDocStatus As Object = "IN DEVELOPMENT"
                ABMpropsDict.Add(ABMPropDefArray(UBound(ABMPropDefArray)), ABMDocStatus)
            End If

            'Load ExplorerUtil
            Dim VaultExplorerUtil As IExplorerUtil = ExplorerLoader.LoadExplorerUtil(m_conn.Server, m_conn.Vault, m_conn.UserID, m_conn.Ticket)

            'change properties
            If UBound(WIPFileIdList) <> -1 Then
                For Each WIPindfile As File In WIPfilelist
                    Processing = True
                    VaultExplorerUtil.UpdateFileProperties(WIPindfile, WIPpropsDict)
                    Processing = False
                Next WIPindfile
            End If
            If UBound(ABMFileIdList) <> -1 Then
                For Each ABMindfile As File In ABMfilelist
                    Processing = True
                    VaultExplorerUtil.UpdateFileProperties(ABMindfile, ABMpropsDict)
                    Processing = False
                Next ABMindfile
            End If

            'Close ExplorerUtil
            VaultExplorerUtil = Nothing

            'loggout of the vault server
            VDF.Vault.Library.ConnectionManager.LogOut(m_conn)
        End Sub
        Private Sub Add_property_values(ByVal sender As Object, ByVal e As UpdateFileLifeCycleStateCommandEventArgs)

            'Get a list of master ids
            Dim ChkFileIdList(-1) As Long
            Dim AppFileIdList(-1) As Long
            Dim RelFileIdList(-1) As Long
            Dim WIPRelFileIdList(-1) As Long
            'Get a list of the master ids for files that are trnsitioning to the "Released" state of the "ab main" lifecycle.
            For i As Byte = LBound(e.FileMasterIds) To UBound(e.FileMasterIds)
                If e.ToStateIds(i) = 51 Then
                    ReDim Preserve ChkFileIdList(UBound(ChkFileIdList) + 1)
                    ChkFileIdList(UBound(ChkFileIdList)) = e.FileMasterIds(i)
                End If
                If e.ToStateIds(i) = 52 Then
                    ReDim Preserve AppFileIdList(UBound(AppFileIdList) + 1)
                    AppFileIdList(UBound(AppFileIdList)) = e.FileMasterIds(i)
                End If
                If e.ToStateIds(i) = 48 Then
                    ReDim Preserve RelFileIdList(UBound(RelFileIdList) + 1)
                    RelFileIdList(UBound(RelFileIdList)) = e.FileMasterIds(i)
                End If
                If e.ToStateIds(i) = 30 Then
                    ReDim Preserve WIPRelFileIdList(UBound(WIPRelFileIdList) + 1)
                    WIPRelFileIdList(UBound(WIPRelFileIdList)) = e.FileMasterIds(i)
                End If
            Next i
            If UBound(ChkFileIdList) = -1 And UBound(AppFileIdList) = -1 And UBound(RelFileIdList) = -1 And UBound(WIPRelFileIdList) = -1 Then
                Return
            End If

            'establish a connection to vault with current users details
            Dim results As VDF.Vault.Results.LogInResult
            Dim curuser As String = System.Environment.UserName
            results = VDF.Vault.Library.ConnectionManager.LogIn("xxxxx", "xxxxx", "", "", VDF.Vault.Currency.Connections.AuthenticationFlags.WindowsAuthentication, Nothing)
            If Not results.Success Then
                Return
            End If
            Dim m_conn As Connection = results.Connection

            'get list of latest files from the list of master ids
            Dim Chkfilelist As File()
            Dim Appfilelist As File()
            Dim Relfilelist As File()
            Dim WIPRelfilelist As File()
            If UBound(ChkFileIdList) <> -1 Then
                Chkfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(ChkFileIdList)
            End If
            If UBound(AppFileIdList) <> -1 Then
                Appfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(AppFileIdList)
            End If
            If UBound(RelFileIdList) <> -1 Then
                Relfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(RelFileIdList)
            End If
            If UBound(WIPRelFileIdList) <> -1 Then
                WIPRelfilelist = m_conn.WebServiceManager.DocumentService.GetLatestFilesByMasterIds(WIPRelFileIdList)
            End If

            'Make dictionary
            curuser = StrConv(Replace(curuser, ".", " "), VbStrConv.Uppercase)
            Dim CurUserObj As Object = curuser
            Dim CurDate As Date = Now
            Dim CurDateObj As Object = CurDate
            Dim CurDateText As Object = CurDate.ToShortDateString

            'make a dictinary of properties that are going to change to for checking
            Dim ChkPropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            If UBound(ChkFileIdList) <> -1 Then
                Dim ChkPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"Issued By-{6e2f891e-904a-425f-9878-db0278b4a458}", "Issued Date-{a53a81dc-0b1f-42aa-83f9-a98bc811a5e1}", "3be98b49-848b-4559-867f-632a4ce576eb", "84cc39eb-05d1-4Db1-8d66-3Fb9e0f03df6"})
                Dim ChkDocStatus As Object = "FOR REVIEW"
                ChkPropsDict.Add(ChkPropDefArray(0), CurUserObj)
                ChkPropsDict.Add(ChkPropDefArray(1), CurDateObj)
                ChkPropsDict.Add(ChkPropDefArray(2), CurDateText)
                ChkPropsDict.Add(ChkPropDefArray(3), ChkDocStatus)
            End If

            'make a dictinary of properties that are going to change to for approval
            Dim AppPropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            If UBound(AppFileIdList) <> -1 Then
                Dim AppPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"CheckedBy", "Checked date-{0172e3de-5a6e-47c7-b68d-3fd057def917}", "50a26fa2-c547-4a82-aaa1-7960da2ae827", "84cc39eb-05d1-4Db1-8d66-3Fb9e0f03df6"})
                Dim AppDocStatus As Object = "FOR REVIEW"
                AppPropsDict.Add(AppPropDefArray(0), CurUserObj)
                AppPropsDict.Add(AppPropDefArray(1), CurDateObj)
                AppPropsDict.Add(AppPropDefArray(2), CurDateText)
                AppPropsDict.Add(AppPropDefArray(3), AppDocStatus)
            End If

            'make a dictinary of properties that are going to change to Released
            Dim RelPropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            If UBound(RelFileIdList) <> -1 Then
                Dim RelPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"Approved by-{6f303c25-1e20-4f90-9461-d43498c65f79}", "Approval date-{576aa6d6-6e6a-411c-9575-d35ab5a5ba03}", "Approval Date Drawing-{1d7fa910-e347-4e8f-87ae-45c1412ba4e0}", "84cc39eb-05d1-4Db1-8d66-3Fb9e0f03df6"})
                Dim RelDocStatus As Object = "RELEASED"
                RelPropsDict.Add(RelPropDefArray(0), CurUserObj)
                RelPropsDict.Add(RelPropDefArray(1), CurDateObj)
                RelPropsDict.Add(RelPropDefArray(2), CurDateText)
                RelPropsDict.Add(RelPropDefArray(3), RelDocStatus)
            End If

            'make a dictinary of properties that are going to change to Released in the WIP lifecycle
            Dim WIPRelPropsDict As Dictionary(Of PropDef, Object) = New Dictionary(Of PropDef, Object)
            If UBound(WIPRelFileIdList) <> -1 Then
                Dim WIPRelPropDefArray As PropDef() = m_conn.WebServiceManager.PropertyService.FindPropertyDefinitionsBySystemNames("FILE", New String() _
                {"Issued By-{6e2f891e-904a-425f-9878-db0278b4a458}", "Issued Date-{a53a81dc-0b1f-42aa-83f9-a98bc811a5e1}", "3be98b49-848b-4559-867f-632a4ce576eb", "84cc39eb-05d1-4Db1-8d66-3Fb9e0f03df6"})
                Dim WIPRelDocStatus As Object = "CONCEPT RELEASE"
                WIPRelPropsDict.Add(WIPRelPropDefArray(0), CurUserObj)
                WIPRelPropsDict.Add(WIPRelPropDefArray(1), CurDateObj)
                WIPRelPropsDict.Add(WIPRelPropDefArray(2), CurDateText)
                WIPRelPropsDict.Add(WIPRelPropDefArray(3), WIPRelDocStatus)
            End If

            'Load ExplorerUtil
            Dim VaultExplorerUtil As IExplorerUtil = ExplorerLoader.LoadExplorerUtil(m_conn.Server, m_conn.Vault, m_conn.UserID, m_conn.Ticket)

            'change properties
            If UBound(ChkFileIdList) <> -1 Then
                For Each IndChkFile As File In Chkfilelist
                    VaultExplorerUtil.UpdateFileProperties(IndChkFile, ChkPropsDict)
                Next IndChkFile
            End If
            If UBound(AppFileIdList) <> -1 Then
                For Each IndAppFile As File In Appfilelist
                    VaultExplorerUtil.UpdateFileProperties(IndAppFile, AppPropsDict)
                Next IndAppFile
            End If
            If UBound(RelFileIdList) <> -1 Then
                For Each IndRelFile As File In Relfilelist
                    VaultExplorerUtil.UpdateFileProperties(IndRelFile, RelPropsDict)
                Next IndRelFile
            End If
            If UBound(WIPRelFileIdList) <> -1 Then
                For Each IndWIPRelFile As File In WIPRelfilelist
                    VaultExplorerUtil.UpdateFileProperties(IndWIPRelFile, WIPRelPropsDict)
                Next IndWIPRelFile
            End If

            'Close ExplorerUtil
            VaultExplorerUtil = Nothing

            'loggout of the vault server
            VDF.Vault.Library.ConnectionManager.LogOut(m_conn)
        End Sub
    End Class
0 Likes
Message 3 of 5

Anonymous
Not applicable

Wow! That's a lot of code...

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

Has anyone found a more concise way of accomplishing this?

0 Likes
Message 5 of 5

Anonymous
Not applicable
0 Likes