0 Replies Latest reply: Jul 9, 2012 2:52 AM by Dan-Ketil Jakobsen RSS

    Use of two variables in EDX

    Dan-Ketil Jakobsen



      I have several reports that use EDX. They all use one SQL variable that I send thru the macro.

      Now I have to expand it and add another one as well.

      But I cannot get it to work.


      The macro runs, and it flag no errors.


      Here is the code:(red text = the new parts in the code)

      Hope you have an idea to what might be wrong.



      Sub TriggerEDX()


      Dim objHttp

      Dim strUrl

      Dim strData

      Dim strKeyRequest

      Dim strKeyAwnser

      Dim stringSQL

      Dim stringBatchID



      SET varSQL = ActiveDocument.Variables("vSQL")

      SET varSQL2 = ActiveDocument.Variables("vCIPStepSQL")



          'Set task name

          Dim strTaskName

          strTaskName = "MES_CIP"


          Dim strTaskPassword

          strTaskPassword = inputbox("Please enter task password")


          ' Create a HTTP instance

          Set objHttp = CreateObject("Microsoft.XMLHTTP")


          strUrl = "http://localhost:4720/qtxs.asmx"


          'Get key for  HTTP

          strKeyRequest ="<Global method=""GetTimeLimitedRequestKey"" />"


          'Do HTTP call to server

          objHttp.open "POST",strUrl,false

          objHttp.setRequestHeader "Content-Type","text/xml"

          objHttp.setRequestHeader "Content-Length", Len(strKeyRequest)

          objHttp.Send strKeyRequest


          'Parse the awnser

          Dim strKey

          strKey = ParseKeyAwnser(objHttp.ResponseText)



          'Get the string to send in the request that triggers the task

          Dim strEDXRequest


          strEDXRequest = GetEDXRequestString(strKey,strTaskName,strTaskPassword,varSQL.GetContent.String,varSQL2.GetContent.String)


          'Do the actual request to trigger the task

          objHttp.open "POST",strUrl,false

          objHttp.setRequestHeader "Content-Type","text/xml"

          objHttp.setRequestHeader "Content-Length", Len(strKeyRequest)

          objHttp.Send strEDXRequest


          'Get the awnser, the awnser can contain different things but for now I only care to see if we find success

          dim strAwnser

          strAwnser = objHttp.ResponseText


          'The awnser if success looks like this


          '  <RequestEDXResult>

          '    <TaskStartResult>Success</TaskStartResult>

          '    <Log />

          '  </RequestEDXResult>





          if(Instr(strAwnser,"<TaskStartResult>Success</TaskStartResult>") > 0) then

              msgbox("Loading, please wait!")



          end if



      End Sub


      Function ParseKeyAwnser(strKeyAwnser)

      'The Awnser should look something like this


      '  <GetTimeLimitedRequestKeyResult>ltqFrklyIwdx1zFXIhNE8TT3RnHy6Peq</GetTimeLimitedRequestKeyResult>



      Dim intStartPos

      Dim IntKeyLen


      'Get the starting and the end position of the key

      intStartPos = InStr(strKeyAwnser,"<GetTimeLimitedRequestKeyResult>")+Len("<GetTimeLimitedRequestKeyResult>")

      intKeyLen = InStrRev(strKeyAwnser,"</GetTimeLimitedRequestKeyResult>") - intStartPos


      'Get and return the key

      ParseKeyAwnser = Mid(strKeyAwnser,intStartPos,intKeyLen)


      End Function


      Function GetEDXRequestString(strRequestKey,strTaskName,strTaskPassword,stringSQL,stringBatchID)

      'The request to send look like this

      '<Global method="RequestEDX" key="RJtp/RJZAjAd3IlwEUTEKhQgiMafRoze">



        '<i_VariableName /><i_VariableName />

        '<i_VariableValueList /><i_VariableValueList />



      'Make the string and insert the key

      GetEDXRequestString = "<Global method=""RequestEDX"" key=""" & strRequestKey &  """><i_TaskIDOrTaskName>" & strTaskName & "</i_TaskIDOrTaskName><i_Password>" & strTaskPassword & "</i_Password><i_VariableName >vSQL;vCIPStepSQL</i_VariableName ><i_VariableValueList ><string>" & stringSQL & ";" & stringBatchID & "</string></i_VariableValueList ></Global>"


      End Function