8 Replies Latest reply: May 11, 2012 11:00 AM by Kumar Gauraw RSS

    Executing QlikView EDX task using different username

      Hi,

       

      i have an EDX task created in the QMC, i need to execute it remotely.

      i am using my system to run the task, but it failed because of authentication, i am not there in QlikView EDX group to run the task.

      but i have one username and password, which is there in EDX group. so how can i run the task using this credentials?

      can i add this credentials in qmsedx.exe.config file?

      or can i login as this username and run?

      how can i run it?

        • Re: Executing QlikView EDX task using different username
          Bill Britt

          Here is something to look at.  Have not tried this with version 11

           

          '-----------------------------------------------------------------------------

          '- Start a QlikView Publisher EDX Task

          '-

          '- This sample is provided 'AS-IS', without any express or implied warranty.

          '- In no event will the authors be held liable for any damages arising from

          '- the use of this sample code.

          '-

          '- Author: MRW (http://www.qlik.com/)

          '-

          '-

          '- Required Parameters:

          '-    /t:taskName

          '-    /p:password

          '-

          '- NB, taskName is case-sensitive and may contain spaces if quoted.

          '-

          '- The user invoking this script must be recognised by the QDS host as a

          '- member of ".\QlikView EDX" or ".\QlikView Administrators" groups

          '- to trigger an EDX task.

          '-

          '- If using the "/w" parameter to wait for the Task to Complete, then the

          '- user invoking this script must be a member of ".\QlikView Administrators".

          '-

          '- Alternatively you can record credentials in the USERNAME and PASSWORD

          '- constants below.

          '-

          '-----------------------------------------------------------------------------

          option explicit

          on error resume next

           

          '-----------------------------------------------------------------------------

          '- Global Constants

          '-----------------------------------------------------------------------------

          ' RequestEDX TaskStartResultCode

          CONST SUCCESS                   = 0    ' Task Request was submitted successfully

          CONST TASKNOTFOUND              = 1

          CONST TASKISALREADYRUNNING      = 2

          CONST NOEDXTRIGGERFOUND         = 3

          CONST OTHERERROR                = 9

           

          ' GetTaskStatus Status

          CONST WAITING                   = 0    ' implies Finished, and waiting for next schedule

          CONST RUNNING                   = 90    ' still running

          CONST FINISHEDWITHWARNINGS      = 91

          CONST FINISHEDWITHERRORS        = 92

           

          CONST FATALERROR                = 100    ' caused by errors POSTing commands to QDS

           

          CONST DEFAULT_ITERATIONS        = 1920

          CONST DEFAULT_DELAY             = 15

          CONST DEFAULT_QDS               = "http://localhost:4720/qtxs.asmx"

           

          ' member of "QlikView Administrators". If null, then the user who invoked

          ' the script is used for interactions with the QDS.

          CONST USERNAME                  = ""    ' "domain\user"

          CONST PASSWORD                  = ""    ' "password"

           

          '-----------------------------------------------------------------------------

          '- Global Variables

          '-----------------------------------------------------------------------------

          DIM xmlHttp        'Object used for connectivity to QDS

          DIM xml            'Object container for XML response from QDS

          DIM xmlObj        'Object container for XML response from QDS

           

          DIM EDXTASK        'name of Task to be triggered

          DIM EDXPSWD        'password of Task

          DIM WAIT        'boolean whether to wait for Completion or not

          DIM ITERATIONS        'number of Iterations to wait for Task Completion

          DIM DELAY        'number of seconds between Iterations

          DIM ShowMessages    'boolean whether to show Logged status messages

           

          DIM QDS            'URL to QlikView Distribution

          DIM METHOD        'XML command string

           

          DIM node        'counter used to iterate through XML response

          DIM i            'iterations of GetTaskStatus()

          DIM TaskStartResult    'initial String  result of RequestEDX()

          DIM TaskStartResultCode    'initial Integer result of RequestEDX()

          DIM LastLogMsg        'Trailing lines from Task Log

          DIM GetTaskStatus    'Waiting/Running/etc

          DIM Message        'Log Message is split using Tab Delimiter

          DIM Finished        'boolean whether Task has completed

           

          DIM RC            'Return Code, produces Windows %ErrorLevel%

           

          '-----------------------------------------------------------------------------

          '- Command-line Arguments

          '-----------------------------------------------------------------------------

          Sub Usage()

              WScript.Echo "Submit a Task Execution request to QlikView Publisher."

              WScript.Echo " "

              Wscript.Echo Wscript.ScriptName & " /t:TaskName /p:Password [/w [/i:iterations] [/d:delay]] [/u:url] [/m]"

              WScript.Echo " "

              WScript.Echo "  /t     TaskName associated with Trigger"

              WScript.Echo "  /p     Password of EDX Trigger"

              WScript.Echo " "

              WScript.Echo "  /w     Wait for Task Completion Status"

              WScript.Echo "    /i   Iterations to check for completion status (default = " & DEFAULT_ITERATIONS & ")"

              WScript.Echo "    /d   Delay between iterations (default = " & DEFAULT_DELAY & ") in seconds"

              WScript.Echo "         hence Timeout after " & DEFAULT_ITERATIONS & "*" & DEFAULT_DELAY & "=" & DEFAULT_ITERATIONS * DEFAULT_DELAY & " seconds"

              WScript.Echo " "

              WScript.Echo "  /u     URL of Distribution Service (default = " & DEFAULT_QDS & ")"

              WScript.Echo " "

              WScript.Echo "  /m     Show Status Text"

              WScript.Echo "  /h     This helptext"

              WScript.Echo "  /e     ErrorLevels produced by this command"

              WScript.Echo " "

              WScript.Echo "Must be invoked by a member of ""QlikView EDX"" or ""QlikView Administrators""."

              WScript.Echo "When using /w then must be invoked by a member of ""QlikView Administrators""."

              WScript.Echo " "

          End Sub

           

          Sub ErrorLevel()

              WScript.Echo "On Submitting a Task"

              WScript.Echo "--------------------"

              WScript.Echo SUCCESS                & chr(9) & "Success, Task Request was submitted successfully"

              WScript.Echo TASKNOTFOUND        & chr(9) & "Task not Found"

              WScript.Echo TASKISALREADYRUNNING    & chr(9) & "Task is already Running"

              WScript.Echo NOEDXTRIGGERFOUND    & chr(9) & "No EDX Trigger Found"

              WScript.Echo OTHERERROR        & chr(9) & "Other Error"

              WScript.Echo " "

              WScript.Echo "On querying Task Status"

              WScript.Echo "-----------------------"

              WScript.Echo WAITING        & chr(9) & "Finished, and waiting for next schedule"

              WScript.Echo RUNNING        & chr(9) & "Still Running"

              WScript.Echo FINISHEDWITHWARNINGS    & chr(9) & "Finished with Warnings"

              WScript.Echo FINISHEDWITHERRORS    & chr(9) & "Finished with Errors"

              WScript.Echo " "

              WScript.Echo "Other"

              WScript.Echo "-----"

              WScript.Echo FATALERROR        & chr(9) & "An HTTP Error occurred connecting to QDS"

              WScript.Echo " "

          End Sub

           

          Sub Info()

              WScript.Echo Wscript.ScriptName

              WScript.Echo "  /t:""" & EDXTASK & """"

              WScript.Echo "  /p:""" & EDXPSWD & """"

           

              if (WAIT = True) then

                 WScript.Echo "  /w"

                 WScript.Echo "  /i:" & ITERATIONS

                 WScript.Echo "  /d:" & DELAY

              end if

           

              WScript.Echo "  /u:" & QDS

          End Sub

           

           

          ' Show command-line Help

          if Wscript.Arguments.Named.Exists("h") then

              Usage()

              ErrorLevel()

              Wscript.Quit OTHERERROR

          end if

           

          ' Show Error Levels

          if Wscript.Arguments.Named.Exists("e") then

              ErrorLevel()

              Wscript.Quit OTHERERROR

          end if

           

          ' Task Name

          if Wscript.Arguments.Named.Exists("t") then

              EDXTASK = Wscript.Arguments.Named("t")

          else

              Usage()

              Wscript.Quit OTHERERROR

          end if

           

          ' Trigger Password

          if Wscript.Arguments.Named.Exists("p") then

              EDXPSWD = Wscript.Arguments.Named("p")

          else

              Usage()

              Wscript.Quit OTHERERROR

          end if

           

          ' Wait for Task Completion Status

          if Wscript.Arguments.Named.Exists("w") then

              WAIT = True

           

              ' How many iterations of checking the Task Status

              if Wscript.Arguments.Named.Exists("i") then

                  ITERATIONS = CInt(Wscript.Arguments.Named("i"))

                  if ITERATIONS < DEFAULT_ITERATIONS then ITERATIONS = DEFAULT_ITERATIONS

              else

                  ITERATIONS = DEFAULT_ITERATIONS

              end if

           

              ' How many seconds delay between iterations

              if Wscript.Arguments.Named.Exists("d") then

                  DELAY = CInt(Wscript.Arguments.Named("d"))

                  if DELAY < DEFAULT_DELAY then DELAY = DEFAULT_DELAY

              else

                  DELAY = DEFAULT_DELAY

              end if

          else

              WAIT = False

          end if

           

          ' Show Log Messages

          if Wscript.Arguments.Named.Exists("m") then

              ShowMessages = True

          else

              ShowMessages = False

          end if

           

          ' URL of the QlikView Distribution Service

          if Wscript.Arguments.Named.Exists("u") then

              QDS = Wscript.Arguments.Named("u")

          else

              QDS = DEFAULT_QDS

          end if

           

          ' Show command-line Help

          if Wscript.Arguments.Named.Exists("x") then

              Info()

          end if

           

          '-----------------------------------------------------------------------------

          '- GetTimeLimitedRequestKey

          '-----------------------------------------------------------------------------

          Function GetTimeLimitedRequestKey()

              'Request a Time Limited Ticket:

              '  <Global method="GetTimeLimitedRequestKey"/>

              '

              'The Answer should look something like:

              '  <GetTimeLimitedRequestKey>

              '    <GetTimeLimitedRequestKeyResult>ltqFrklyIwdx1zFXIhNE8TT3RnHy6Peq</GetTimeLimitedRequestKeyResult>

              '  </GetTimeLimitedRequestKey>

           

              DIM METHOD 'XML command string

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

           

              ' Submit request to the URL via HTTP

              xmlHttp.open "POST",QDS,false,USERNAME,PASSWORD

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

              xmlHttp.setRequestHeader "Content-Length", Len(METHOD)

              xmlHttp.Send METHOD

           

              select case xmlHttp.Status

                  case 200:

                      ' Successful response from GetTimeLimitedRequestKey

           

                      ' show the response

                      'WScript.Echo xmlHttp.responseText

                      'WScript.Echo ""

           

                      ' Load the Response into an XML object

                      xml.async = false

                      xml.loadXML(xmlHttp.responseText)

           

                      set xmlObj = xml.SelectNodes("//GetTimeLimitedRequestKey")

                      for node = 0 to (xmlObj.length -1)

                          if xmlObj.item(node).nodeName = "GetTimeLimitedRequestKey" then

                              GetTimeLimitedRequestKey = xmlObj.item(node).text

                         end if

                      next 'node

           

                  case 401:

                      WScript.Echo "ERROR: The credentials for QDS (" & QDS & ") are incorrect."

                      Wscript.Quit FATALERROR

           

                  case 403:

                      WScript.Echo "ERROR: User is not authorised to interact with QDS."

                      Wscript.Quit FATALERROR

           

                  case 404:

                      WScript.Echo "ERROR: The URL for QDS (" & QDS & ") is incorrect."

                      Wscript.Quit FATALERROR

           

                  case 503:

                      WScript.Echo "ERROR: The QDS (" & QDS & ") is unavailable."

                      Wscript.Quit FATALERROR

           

                  case 12029:

                      WScript.Echo "ERROR: The QDS (" & QDS & ") is not accessible."

                      Wscript.Quit FATALERROR

           

                  case else

                      WScript.Echo "ERROR: An error (" & xmlHttp.Status & ") occurred trying to access the QDS."

                      Wscript.Quit FATALERROR

           

              end select 'xmlHttp

          End Function

           

          '-----------------------------------------------------------------------------

          '- RequestEDX

          '-----------------------------------------------------------------------------

          ' The request to send looks like this:

          '

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

          '    <i_TaskIDOrTaskName>MyTaskName</i_TaskIDOrTaskName>

          '    <i_Password>MyTaskPassword</i_Password>

          '    <i_VariableName />

          '    <i_VariableValueList />

          '  </Global>

           

          set xmlHttp = CreateObject("Microsoft.XMLHTTP")

          set xml = createobject("Microsoft.XMLDOM")

          set xmlObj = createobject("Microsoft.XMLDOM")

           

          METHOD =           "<Global method=""RequestEDX"" key=""" & GetTimeLimitedRequestKey() &  """>"

          METHOD = METHOD & "<i_TaskIDOrTaskName>" & EDXTASK & "</i_TaskIDOrTaskName>"

          METHOD = METHOD & "<i_Password>" & EDXPSWD & "</i_Password>"

          METHOD = METHOD & "<i_VariableName></i_VariableName><i_VariableValueList></i_VariableValueList>"

          METHOD = METHOD & "</Global>"

          'WScript.Echo METHOD

          'WScript.Echo ""

           

          DIM AsAt ' This is when we submitted the EDX Request

          AsAt = Now()

           

          ' Submit request to the QDS via HTTP

          xmlHttp.open "POST",QDS,false,USERNAME,PASSWORD

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

          xmlHttp.setRequestHeader "Content-Length", Len(METHOD)

          xmlHttp.Send METHOD

           

          select case xmlHttp.Status

              case 200:

                  ' Successful response from RequestEDX

           

                  ' show the response

                  'WScript.Echo xmlHttp.responseText

                  'WScript.Echo ""

           

                  ' Load the Response into an XML object

                  xml.async = false

                  xml.loadXML(xmlHttp.responseText)

           

                  ' Parse the XML Response extracting Status, Log, etc

                  TaskStartResult = ""

                  set xmlObj = xml.SelectNodes("//RequestEDX/RequestEDXResult/*")

                  for node = 0 to (xmlObj.length -1)

                      select case xmlObj.item(node).nodeName

                          case "TaskStartResult":

                              TaskStartResult = xmlObj.item(node).text

           

                              select case TaskStartResult

                                  case "Success":

                                      TaskStartResultCode = SUCCESS

           

                                  case "TaskNotFound":

                                     TaskStartResultCode = TASKNOTFOUND

           

                                  case "TaskIsAlreadyRunning":

                                      TaskStartResultCode = TASKISALREADYRUNNING

           

                                  case "NoEDXTriggerFound":

                                      TaskStartResultCode = NOEDXTRIGGERFOUND

           

                                  case "OtherError":

                                      TaskStartResultCode = OTHERERROR

           

                                  case else

                                      TaskStartResultCode = OTHERERROR

           

                              end select 'TaskStartResult

                              RC = TaskStartResultCode

           

                          case "TaskStartResultCode":

                              select case xmlObj.item(node).text

                                  case "0":

                                      TaskStartResultCode = SUCCESS

           

                                  case "1":

                                      TaskStartResultCode = TASKNOTFOUND

           

                                  case "2":

                                      TaskStartResultCode = TASKISALREADYRUNNING

           

                                  case "3":

                                      TaskStartResultCode = NOEDXTRIGGERFOUND

           

                                  case "9":

                                      TaskStartResultCode = OTHERERROR

           

                                  case else

                                      TaskStartResultCode = OTHERERROR

           

                              end select 'TaskStartResultCode

                              RC = TaskStartResultCode

           

                          case "Log":

                              ' Message(0) is timestamp

                              ' Message(1) is errorLevel

                              ' Message(2) is errorText

                              Message = Split( xmlObj.item(node).text, chr(9))

           

                      end select 'nodeName

                  next 'iteration

           

              case 401:

                  WScript.Echo "ERROR: The credentials for QDS (" & QDS & ") are incorrect."

                  Wscript.Quit FATALERROR

           

              case 403:

                  WScript.Echo "ERROR: User is not authorised to request EDX tasks."

                  Wscript.Quit FATALERROR

           

              case 404:

                  WScript.Echo "ERROR: The URL for QDS (" & QDS & ") is incorrect."

                  Wscript.Quit FATALERROR

           

              case 503:

                  WScript.Echo "ERROR: The QDS (" & QDS & ") is unavailable."

                  Wscript.Quit FATALERROR

           

              case 12029:

                  WScript.Echo "ERROR: The QDS (" & QDS & ") is not accessible."

                  Wscript.Quit FATALERROR

           

              case else

                  WScript.Echo "ERROR: An error (" & xmlHttp.Status & ") occurred trying to access the QDS."

                  Wscript.Quit FATALERROR

           

          end select 'xmlHttp

           

          'WScript.Echo "========================================================="

          'WScript.Echo "QDS URL:        [" & QDS & "]"

          'WScript.Echo ""

          'WScript.Echo "EDX Task:            [" & EDXTASK & "]"

          'WScript.Echo "EDX Password:        [" & EDXPSWD & "]"

          'WScript.Echo "                    -----------------------"

          WScript.Echo AsAt & chr(9) & "[" & TaskStartResult & "]"

           

          if (ShowMessages = True) and (UBound(Message) > 0) then

              WScript.Echo " "

              WScript.Echo Message(2)

              WScript.Echo " "

          end if

           

           

          '-----------------------------------------------------------------------------

          '- GetTaskStatus

          '-----------------------------------------------------------------------------

          i = 0

          Finished = False

          do while (TaskStartResultCode = SUCCESS) AND (WAIT = True) AND (i < ITERATIONS) AND Not Finished

              wscript.sleep( DELAY * 1000)

           

           

              'The request to send looks like this:

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

              '    <TaskNameOrId>MyTaskName</TaskNameOrId>

              '  </Global>

           

              METHOD =           "<Global method=""GetTaskStatus"" key=""" & GetTimeLimitedRequestKey() &  """>"

              METHOD = METHOD & "<TaskNameOrId>" & EDXTASK & "</TaskNameOrId>"

              METHOD = METHOD & "</Global>"

              'WScript.Echo METHOD

              'WScript.Echo ""

           

              ' This is when we queried the Task Status

              AsAt = Now()

           

              ' Submit request to the QDS via HTTP

              xmlHttp.open "POST",QDS,false,USERNAME,PASSWORD

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

              xmlHttp.setRequestHeader "Content-Length", Len(METHOD)

              xmlHttp.Send METHOD

           

              select case xmlHttp.Status

                  case 200:

                      ' Successful response from GetTaskStatus

           

                      ' show the response

                      'WScript.Echo xmlHttp.responseText

                      'WScript.Echo ""

           

                      ' Load the Response into an XML object

                      xml.async = false

                      xml.loadXML(xmlHttp.responseText)

           

                      ' Parse the XML Response extracting Status, Log, etc

                      set xmlObj = xml.SelectNodes("//GetTaskStatus/GetTaskStatusResult/TaskStatus/*")

                      for node = 0 to (xmlObj.length -1)

                          'WScript.Echo xmlObj.item(node).nodeName & " = " & chr(9) & "[" & xmlObj.item(node).text & "]"

           

                          select case xmlObj.item(node).nodeName

                              case "Status":

                                  GetTaskStatus = xmlObj.item(node).text

           

                                  select case GetTaskStatus

                                      case "Waiting":

                                          Finished = True

                                          RC = WAITING

                                          WScript.Echo AsAt & chr(9) & "[Finished]"

           

                                      case "Running":

                                          Finished = False

                                          RC = RUNNING

                                          WScript.Echo AsAt & chr(9) & "[Running...]"

           

                                      case "FinishedWithWarnings":

                                          Finished = True

                                          RC = FINISHEDWITHWARNINGS

                                          WScript.Echo AsAt & chr(9) & "[" & GetTaskStatus & "]"

           

                                      case "FinishedWithErrors":

                                          Finished = True

                                          RC = FINISHEDWITHERRORS

                                          WScript.Echo AsAt & chr(9) & "[" & GetTaskStatus & "]"

           

                                      case else

                                          Finished = True

                                          RC = OTHERERROR

                                          WScript.Echo AsAt & chr(9) & "[Error!]"

           

                                  end select 'GetTaskStatus

           

                              case "LastLogMsg":

                                  LastLogMsg = xmlObj.item(node).text

                                  if ShowMessages = True then

                                      WScript.Echo " "

                                      WScript.Echo LastLogMsg

                                      WScript.Echo " "

                                  end if

           

                          end select 'nodeName

                      next 'node

           

                  case 401:

                      WScript.Echo "ERROR: The credentials for QDS (" & QDS & ") are incorrect."

                      Wscript.Quit FATALERROR

           

                  case 403:

                      WScript.Echo "ERROR: User is not authorised to Get Task Status."

                      Wscript.Quit FATALERROR

           

                  case 404:

                      WScript.Echo "ERROR: The URL for QDS (" & QDS & ") is incorrect."

                      Wscript.Quit FATALERROR

           

                  case 503:

                      WScript.Echo "ERROR: The QDS (" & QDS & ") is unavailable."

                      Wscript.Quit FATALERROR

           

                  case 12029:

                      WScript.Echo "ERROR: The QDS (" & QDS & ") is not accessible."

                      Wscript.Quit FATALERROR

           

                  case else

                      WScript.Echo "ERROR: An error (" & xmlHttp.Status & ") occurred trying to access the QDS."

                      Wscript.Quit FATALERROR

           

              end select 'xmlHttp

           

              i = i + 1

          Loop 'GetTaskStatus

           

          'WScript.Echo "========================================================="

           

          '-----------------------------------------------------------------------------

          '- End

          '-----------------------------------------------------------------------------

          xmlObj  = null

          xml     = null

          xmlHttp = null

           

          WScript.Quit RC