2 Replies Latest reply on Aug 7, 2018 12:53 PM by Tim Webb

    in api, how to cancel user change state request?

    Win Lai

      Hi,

       

      I need to do some checking when user change state, and I write some code in EdmCmdType.EdmCmd_PreState session, now, when the checking fails, how can I cancel the user change state request? does api support it? Please help, thanks a lot.

       

      Best regards,

      Andrew

        • Re: in api, how to cancel user change state request?
          Tim Webb

          Hi Win,

           

          Here's some code for you. It's a complete vb.net add-in that will block the transition if the "part number" is blank. Let me know if it works for you.

           

          Tim CEPA

          Believe in The Q!

          Get PDM answers now on our Live Chat!

           

          '===========================code below=========================

          Imports EdmLib

           

          Public Class BlockTransition

              Implements IEdmAddIn5

           

              Public Sub GetAddInInfo(ByRef poInfo As EdmLib.EdmAddInInfo, ByVal poVault As EdmLib.IEdmVault5, ByVal poCmdMgr As EdmLib.IEdmCmdMgr5) Implements EdmLib.IEdmAddIn5.GetAddInInfo

                  'Just some information for the Administrate Add-ins dialog box

                  poInfo.mbsAddInName = "BlockTransition"

                  poInfo.mbsCompany = "equivaQ Software, LLC."

                  poInfo.mbsDescription = "Blocks a transition if certain variables on the datacard are empty."

                  poInfo.mlAddInVersion = 1

                  poInfo.mlRequiredVersionMajor = 13

                  poInfo.mlRequiredVersionMinor = 0

           

                  poCmdMgr.AddHook(EdmCmdType.EdmCmd_PreState)

           

              End Sub

           

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

                  Try

                      Dim variablename As String = "Part Number"

                      If poCmd.meCmdType = EdmCmdType.EdmCmd_PreState Then

                          Dim vault As IEdmVault12 = Nothing

                          Dim file As IEdmFile5 = Nothing

                          Dim folder As IEdmFolder5 = Nothing

                          Dim Ctr As Integer = 0

                          vault = DirectCast(poCmd.mpoVault, IEdmVault12)

                          For Ctr = 0 To UBound(ppoData)

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

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

                              Dim vars As IEdmEnumeratorVariable10 = file.GetEnumeratorVariable

                              Dim ConfigNames As IEdmStrLst5 = DirectCast(ppoData(0), EdmCmdData).mpoExtra

                              Dim Config As String

                              If IsConfigInList(ConfigNames, "@") Then

                                  Config = "@"

                              Else

                                  Config = ""

                              End If

                              Dim varvalue As Object = Nothing

                              If vars.GetVar2(variablename, Config, folder.ID, varvalue) Then

                                  If varvalue.ToString.Length = 0 Then

                                      poCmd.mbCancel = True

                                      MsgBox("Please make sure the '" & variablename & "' field is completed before transitioning.", MsgBoxStyle.Exclamation, "Incomplete card values")

                                      Exit Sub

                                  End If

                              End If

                          Next Ctr

                      End If

                  Catch ex As Runtime.InteropServices.COMException

                      MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                  Catch ex As Exception

                      MsgBox(ex.Message)

                  End Try

              End Sub

           

              Private Function IsConfigInList(ByVal ConfigNames As IEdmStrLst5, ByVal ConfigName As String) As Boolean

                  IsConfigInList = False

                  Try

                      Dim CurConfig As String

                      Dim Pos As IEdmPos5 = ConfigNames.GetHeadPosition()

                      While Not Pos.IsNull

                          CurConfig = ConfigNames.GetNext(Pos)

                          If CurConfig = ConfigName Then

                              IsConfigInList = True

                              Exit While

                          End If

                      End While

                      Return IsConfigInList

                  Catch ex As Runtime.InteropServices.COMException

                      MsgBox("HRESULT = 0x" + ex.ErrorCode.ToString("X") + vbCrLf + ex.Message)

                      Return False

                  Catch ex As Exception

                      MsgBox(ex.Message)

                      Return False

                  End Try

              End Function

          End Class