4 Replies Latest reply on Mar 16, 2016 9:40 PM by Paul Smith

    Only allow run task on approved versions

    Paul Smith

      Hi,

       

      I'm setting up a new Convert task. Is there a way to prevent the task from running if an attempt is made to run it on a version that is not approved.

       

      The intent is for people to get an "Approved" version of the file before they run the task, where approved is a specific state in our workflow. I would like there to be a fail-safe such that if somebody does not "Get Version" to a version where the file was approved before they run the task, that the task will not run.

       

      If there is somewhere in the Convert task properties that could do this, that would be great.

      If not, is there a chance it's a few simple lines in the script? Such as, if the source file status is not equal to "Approved" then terminate. (I have very limited coding experience)

        • Re: Only allow run task on approved versions
          Prasad Bhonsule

          Hi Paul, apologies if I have misunderstood your intent, but why not have this set up as part of the workflow? If approved is a specific state in your workflow then have the task run on the transition that goes to approved. Or if you want it specifically after approved, then create a workflow state after approved eg "published" and configure the task to run then?

           

          Kind regards,

           

          Prasad

            • Re: Only allow run task on approved versions
              Paul Smith

              Hi Prasad,

               

              You have understood correctly. Unfortunately we have a few hundred files in a non-Approved state at the moment and our manufacturing department wants to start converting the files. Engineering don't have the resources currently to review and approve the files so for now we want to let manufacturing do it themselves, but we want to make sure they used previously approved versions of the files.

               

              A good suggestion though, and one we are working on, unfortunately we dramatically underestimated how much work this would be for us.

               

              Thanks,

              Paul

            • Re: Only allow run task on approved versions
              Paul Smith

              Hi,

               

              I've found a previous thread where someone wanted to use variables on the data card in the save to FileName which I copied and modified to attempt to achieve what I need. There is a routine called LoginToVault as follows:

               

              '********************************************

              Private Sub LoginToVault()

                On Error GoTo ErrHand

                Dim strTempVaultName As String

                Dim strVaultName As String

                strTempVaultName = "<VaultPath>"

                i = Len(strTempVaultName)

                j = InStrRev(strTempVaultName, "\")

                strVaultName = Right(strTempVaultName, i - j)

                Set vault = CreateObject("ConisioLib.EdmVault")

                vault.LoginAuto strVaultName, 0

               

               

                Exit Sub

               

               

                ErrHand:

                If Not vault Is Nothing Then

                Dim errname As String

                Dim errdesc As String

                vault.GetErrorString Err.Number, errname, errdesc

                Log ("LoginToVault error" & vbCrLf & errname & vbCrLf & errdesc )

                Else

                Log "Error creating file vault interface."

                End If

              End Sub

               

               

              Private Function GetVariableValue(FilePath, VariableName, Configuration)

                On Error GoTo ErrHand

                Dim File As Object

               

                'Get the interface of the file (and its parent folder)

                Dim Folder As Object

                Set File = vault.GetFileFromPath(FilePath, Folder)

               

                'Obtain the variable interface

                Dim pEnumVar As Object

                Set pEnumVar = File.GetEnumeratorVariable

               

               

                Dim Value As Variant

               

               

                If pEnumVar.GetVar(VariableName, Configuration, Value) Then

                GetVariableValue = Value

                Else

                GetVariableValue = ""

                End If

               

               

                Exit Function

               

                ErrHand:

                Dim ename As String

                Dim edesc As String

                vault.GetErrorString Err.Number, ename, edesc

                Log "GetvariableValue error" & vbCrLf & ename & vbCrLf & errdesc

              End Function

              '***********************************************

               

              In the convert routine I've added the section between asterix so it reads as follows:

               

              Sub main()

                

                  On Error GoTo Fail:

                  Set FileSystemObj = CreateObject("Scripting.FileSystemObject")

                  docFileName = "<Filepath>"

               

              '******************************************************

                'Get the vault interface

                Call LoginToVault

               

                'Get Variable Values

                Dim StatusVarValue

                StatusVarValue = GetVariableValue(docFileName, "WPDM_Status", "@")

                 

                   Log "Value of StatusVarValue = " & StatusVarValue

                If StatusVarValue <> “Released” Then

                          Exit Sub

              End If

              '*******************************************************

                    ' Get SW interface object

                  Set swApp = Application.SldWorks

               

               

                  Convert docFileName

                

                  Exit Sub

                  

              Fail:

                  Log "Error while converting file '" & docFileName & "': " & vbCrLf & _

                      "An unexpected error occurred while executing the generated script. Script syntax error?" & vbCrLf & _

                      "Error number: " & Err.Number & vbCrLf & _

                      "Error description: '" & Err.Description & "'" & vbCrLf

                    

              End Sub

               

              Other than that, the Convert script is stock standard.

               

              The intent of the additional code is it will read the data card and if the WPDM_Status is not equal to "Released" it will stop running the task before converting the file.

               

              Running the task on a file where the data card shows "Released" in WPDM_Status results in the task ending before converting the file. The log function added above the If statement returns "Value of StatusVarValue = Released".

               

              So it would seem it is successfully reading the data card, writing Released in the StatusVarValue, but then determining it is not equal to "Released".

               

              Can anyone suggest what could be wrong with the additional code?

               

              Thanks,
              Paul