{
  "Name": "Reportworq - Rest API Run Job Sample 2.4",
  "HasSecurityAccess": false,
  "PrologProcedure": "#****Begin: Generated Statements***\r\n#****End: Generated Statements****\r\n\r\n\r\n# PROCESS Overview and Key Information:\r\n\r\n# Reportworq - Rest API Run Job Sample 2.4\r\n#Copies of the powershell scripts can  be found in the installation directory of Reportworq under Versions\\<insert version folder>\\Scripts - please copy these to a new location to be referenced in this script\r\n#Copies of these TI processes can be found in the installation directory of Reportworq under Versions\\<insert version folder>\\TI_Scripts.\r\n#This TI script calls a powershell script located in your defined path (configured below) using the defined parameters of the TI and sends a call to Reportworq server API to execute the defined job path.  Please note that you do not need to edit anything on the epilog tab of this TI Process.\r\n#----------------------------------------------------------------------------\r\n\r\n\r\n# TI PARAMETERS Included definitions: \r\n\r\n# pApiUrl (String): Api endpoint for running a job from TI. Example: https://localhost:8300/api/v1/run\r\n# pAccessToken (String): Access token required for API access. Within Reportworq – Settings – Reportworq API – grab the Local API access token\r\n# pJobName (String): Reportworq Job Definition (enter the Job Name as seen in Reportworq to run one job file, folder name if you need to run all jobs under that folder)\r\n# pNotificationEmail (String): Email address to send notifications.\r\n# pHoldForDelivery (String): Hold Jobs for Review before Distribution ( true/false ) – by default this is set to False\r\n# pAllowedFileOutputTypes (String): Blank defaults to run exactly as job is setup, but if you want to override the job output you can type in one or many of the following for the format: Excel, PowerPoint, PDF, CSV.  If selecting many types be sure to use comma separation.\r\n# pAllowedDestinationTypes (String): Blank defaults to run exactly as the job is setup, but if you want to override where the job is distributed to you can select one or many of the following from your configured distributors (Email, Teams, Slack, Network Folder, SharePoint). If selecting many types be sure to use comma separation.\r\n# pConvertPowerPointToPdf (String): Convert PPT to PDF for distribution ( true/false )\r\n#pTlsSecurity (String): Supported Tls Security modes used to connect to Reportworq by default these are set to Tls11, Tls12\r\n#pLogLevel (String): Optional Reportworq job log level (Debug/Trace) by default this is blank for regular job run\r\n#----------------------------------------------------------------------------\r\n\r\n\r\n#PATH SETTINGS:\r\n\r\n#   Reportworq Job Request Folder: \r\n#This is the path where the job json request is written by this process, and then referenced in the call to RunApiJob.ps1 file that  will be used to call the Reportworq Server API to run a job.  This is a path/folder that you need to create and then define below.\r\n\r\nJobRequestFolder = 'C:\\Reportworq Scripts\\RunApiJobRequests\\';\r\n\r\n#Reportworq PowerShellScriptFileLocation:\r\n#This is the path to the RunApiJob.ps1 file that will be used to call the Reportworq Server API to run a job.\r\n\r\nPowerShellScriptFolder = 'C:\\Reportworq\\Scripts\"';\r\n\r\n#No edit to below statements needed#\r\nPowerShellScriptFileLocation = PowerShellScriptFolder | 'RunApiJob.ps1';\r\n\r\n#This section will check if the required setup called out above related to the powershell script and job request folder were completed currently.\r\nIF ( FILEEXISTS( JobRequestFolder ) = 0 );\r\n  LOGOUTPUT( 'ERROR', 'Cannot find the required Reportworq job request folder at this location: ' | JobRequestFolder );\r\n  PROCESSERROR;\r\nENDIF;\r\n\r\nIF ( FILEEXISTS( PowerShellScriptFileLocation ) = 0 );\r\n  LOGOUTPUT( 'ERROR', 'Cannot find the required Reportworq RunJob.ps script at this location: ' | PowerShellScriptFileLocation );\r\n  PROCESSERROR;\r\nENDIF;\r\n\r\n#This section is defined to construct the necessary call for the API to understand how to read your parameters – no edits to this section are required by the end user please do not touch# \r\nvDelimiter = ';';\r\nvAllowedOutputFileTypes = '[';\r\nsString = pAllowedFileOutputTypes;\r\nnDelimiterIndex = 1;\r\nWHILE(nDelimiterIndex <> 0);\r\n  nDelimiterIndex = SCAN(vDelimiter, sString);\r\n  IF(nDelimiterIndex = 0);\r\n    sElm = sString;\r\n  ELSE;\r\n    sElm = TRIM(SUBST(sString, 1, nDelimiterIndex - 1));\r\n    sString = TRIM(SUBST(sString, nDelimiterIndex + LONG(vDelimiter), LONG(sString)));\r\n  ENDIF;\r\n  IF(sElm @<> '');\r\n    vAllowedOutputFileTypes = vAllowedOutputFileTypes | '\"' | sElm | '\", ';\r\n  ENDIF;\r\nEND;\r\n\r\nvAllowedOutputFileTypes = vAllowedOutputFileTypes | ']';\r\n\r\nvDelimiter = ';';\r\nvAllowedDestinationTypes = '[';\r\nsString = pAllowedDestinationTypes;\r\nnDelimiterIndex = 1;\r\nWHILE(nDelimiterIndex <> 0);\r\n  nDelimiterIndex = SCAN(vDelimiter,sString);\r\n  IF(nDelimiterIndex = 0);\r\n    sElm = sString;\r\n  ELSE;\r\n    sElm = TRIM(SUBST(sString, 1, nDelimiterIndex - 1));\r\n    sString = TRIM(SUBST(sString, nDelimiterIndex + LONG(vDelimiter), LONG(sString)));\r\n  ENDIF;\r\n  IF(sElm @<> '');\r\n    vAllowedDestinationTypes = vAllowedDestinationTypes | '\"' | sElm | '\", ';\r\n  ENDIF;\r\nEND;\r\n\r\nvAllowedDestinationTypes = vAllowedDestinationTypes | ']';\r\n\r\nvConvertPowerPointToPdf = 'null';\r\nIF(pConvertPowerPointToPdf @<> '');\r\n  vConvertPowerPointToPdf = pConvertPowerPointToPdf;\r\nENDIF;\r\n\r\njson = EXPAND(\r\n'{\r\n   \"name\": \"%pJobName%\",\r\n   \"notification\": \"%pNotificationEmail%\",\r\n   \"holdForDelivery\": %pHoldForDelivery%,\r\n   \"allowedOutputFileTypes\": %vAllowedOutputFileTypes%,\r\n   \"allowedDestinationTypes\": %vAllowedDestinationTypes%,\r\n   \"convertPowerPointToPdf\": %vConvertPowerPointToPdf%,\r\n');\r\n\r\nIF(pLogLevel @<> '');\r\n  IF(pLogLevel @<> 'Debug' & pLogLevel @<> 'Trace');\r\n      LOGOUTPUT( 'ERROR', 'Invalid Reportworq job log level: ' | pLogLevel );\r\n      PROCESSERROR;\r\n  ENDIF;\r\n  json = json | \r\n    EXPAND('\"LogLevel\": \"%pLogLevel%\",');\r\nENDIF;\r\n#----------------------------------------------------------------------------\r\n\r\n\r\n\r\n#JOB PARAMETER OVERRIDES\r\n#This section outlines all the example parameter types and how to format them for parameter overrides.  \r\n#You can uncomment and duplicate parameter templates as needed as it relates to your job definition – this is only required if you need to override a parameter within the job.\r\n#If simply executing the job as long as the job is defined in the parameters you need not touch this section.\r\n#Valid parameter types: list, subset, mdx\r\n\r\n\r\n###########################\r\n# List Parameter Template\r\n###########################\r\n#Below is an example of the List Parameter Template for our Parameter named State.  Please note you do not need to modify pList1Type or pList1Delimiter or the List1JSON.  \r\n#Please note the delimiter by default in the below example is a semicolon, if you want to change this you can change the delimiter to alternative options like a comma. \r\n\r\n#pList1Name = 'State';\r\n#pList1Value = 'NC;SC;GA';\r\n#pList1Delimiter = ';';\r\n\r\n#pList1Type = 'list';\r\n#List1Json = EXPAND(\r\n#'          {\r\n#               \"type\": \"%pList1Type%\",\r\n#               \"name\": \"%pList1Name%\",\r\n#               \"delimiter\": \"%pList1Delimiter%\",\r\n#               \"value\": \"%pList1Value%\"\r\n#            }'\r\n#);\r\n\r\n###########################\r\n# Subset Parameter Template\r\n###########################\r\n#Below is an example of the Subset Parameter Template for our Subset named Department in our TM1 Service called ReporworqRocks.  Please note you do not need to modify the pSubset1Type or the Subset1JSON.  \r\n\r\n#pSubset1Name = 'Department';\r\n#pSubset1Subset = 'ActiveDepartments';\r\n#pSubset1Server = 'ReportworqRocks';\r\n#pSubset1Dimension = 'Department';\r\n\r\n#pSubset1Type = 'subset';\r\n#Subset1json = EXPAND(\r\n#'          {\r\n#               \"type\": \"%pSubset1Type%\",\r\n#               \"name\": \"%pSubset1Name%\",\r\n#               \"server\": \"%pSubset1Server%\",\r\n#               \"dimension\": \"%pSubset1Dimension%\",\r\n#               \"value\": \"%pSubset1Subset%\"\r\n#            }'\r\n#);\r\n\r\n\r\n##########################\r\n# MDX Parameter Template\r\n##########################\r\n#Below is an example of the MDX Parameter Template for our Subset named Department in our TM1 Service called ReporworqRocks.  \r\n#Please note you do not need to modify the pMDX1Type or the MDX1JSON.  \r\n#Any valid MDX statement can be inserted in pMDX1Mdx variable and you can reference other parameters in the MDX as needed.\r\n\r\n#pMDX1Name = 'Department';\r\n#pMDX1Server = 'ReportworqRocks';\r\n#pMDX1Dimension = 'Department';\r\n#pMDX1Alias = 'Name';\r\n#pMDX1Mdx = 'TM1SUBSETALL([' | Department | '])';\r\n\r\n#pMDX1Type = 'mdx';\r\n#mdx1json = EXPAND(\r\n#'          {\r\n#               \"type\": \"%pMDX1Type%\",\r\n#               \"name\": \"%pMDX1Name%\",\r\n#               \"server\": \"%pMDX1Server%\",\r\n#               \"dimension\": \"%pMDX1Dimension%\",\r\n#               \"alias\": \"%pMDX1Alias%\",\r\n#               \"value\": \"%pMDX1Mdx%\"\r\n#            }'\r\n#);\r\n\r\n\r\n#----------------------------------------------------------------------------\r\n\r\n\r\n# Combine Job Json with Parameter(s)\r\n#Below is where you construct the JSON with parameter overrides, you can add additional parameterJSONs as needed or remove as needed.  \r\n#If you have no parameter overrides, then you would leave everything as shown below commented out to have an empty override list that is used in the JSON.\r\n\r\njsonParameters = \r\n'   \"parameters\": \r\n        [ \r\n#             ' | List1Json | ',\r\n#             ' | Subset1Json | ',\r\n#             ' | MDX1Json | '\r\n         ]\r\n';\r\n\r\n\r\n#----------------------------------------------------------------------------\r\n\r\n\r\n\r\n# This section is used to complete the request and is not needed to be modified by the end user – please do not edit anything in this section.\r\n\r\njson = json | \r\n            jsonParameters | '\r\n}';\r\n\r\n# Prevent any leading or trailing quotes\r\nOriginalQuoteCharacter = DatasourceASCIIQuoteCharacter;\r\nDatasourceASCIIQuoteCharacter=' ';\r\n\r\n# Replace any invalid file characters in the file path\r\nsJobNameForFile = '';\r\nsValidFileNameCharacters = '_- 1234567890abcdefghijklmnopqrstuvwxyz';\r\nnCurrIdx = 1;\r\nWHILE (nCurrIdx <= LONG(pJobName));\r\n  sCurrChar = SUBST( pJobName, nCurrIdx, 1 );\r\n\r\n  # Include characters in list above\r\n  IF ( SCAN( LOWER( sCurrChar ), sValidFileNameCharacters ) > 0 );\r\n     sJobNameForFile = sJobNameForFile | sCurrChar;\r\n  ENDIF;\r\n\r\n   # Switch forward and back slashes to underscores\r\n   IF( sCurrChar @= '\\' % sCurrChar @= '/' );\r\n     sJobNameForFile = sJobNameForFile | '_';     \r\n   ENDIF;\r\n   nCurrIdx = nCurrIdx + 1;\r\nEND;\r\n\r\n# Write out file json\r\nJobSpecificationFile = JobRequestFolder | sJobNameForFile | '_Request_' | TIMST( NOW(), '\\Y\\m\\d\\h\\i\\s') | '.txt';\r\nTextOutput( JobSpecificationFile, json );\r\nDatasourceASCIIQuoteCharacter=OriginalQuoteCharacter;\r\n\r\n\r\n",
  "MetadataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
  "DataProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****",
  "EpilogProcedure": "\r\n#****Begin: Generated Statements***\r\n#****End: Generated Statements****\r\n\r\n\r\n#################################################\r\n#  RUN POWERSHELL COMMAND TO EXECUTE JOB \r\n#                USING REPORTWORQ API\r\n#################################################\r\n\r\n#A unique per-run log file (timestamped, plus stderr via 2>&1) so concurrent/repeated runs don't overwrite each other's logs.\r\nCommandToRun = 'CMD /C PowerShell.exe -NonInteractive -ExecutionPolicy Bypass -File \"' |  PowerShellScriptFileLocation | '\" -token \"' | pAccessToken | '\" -url \"' |  pApiUrl | '\" -jobPath \"' | JobSpecificationFile | '\" -tlsSecurity \"' | pTlsSecurity | '\" > \"' | PowerShellScriptFolder | 'RunApiJob_' | TIMST( NOW(), '\\Y\\m\\d\\h\\i\\s' ) | '.log\" 2>&1';\r\nExecuteCommand(CommandToRun,1);\r\n",
  "Parameters": [
    {
      "Name": "pApiUrl",
      "Prompt": "Api endpoint for running a job from TI",
      "Value": "https://localhost:8600/api/v1/run",
      "Type": "String"
    },
    {
      "Name": "pAccessToken",
      "Prompt": "Access token required for API access",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pJobName",
      "Prompt": "Reportworq Job Path (MyFolder/MyJob or MyJob)",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pNotificationEmail",
      "Prompt": "Email address to send notification (optional)",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pHoldForDelivery",
      "Prompt": "Hold Jobs for Review before Distribution (true/false)",
      "Value": "false",
      "Type": "String"
    },
    {
      "Name": "pAllowedFileOutputTypes",
      "Prompt": "Allowed output types for the job, semicolon delimited, blank defaults to all configured (excel/pdf/ppt/csv)",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pAllowedDestinationTypes",
      "Prompt": "Allowed distribution types for the job, semicolon delimited, blank defaults to all configured (file/sharepoint/sheets/email/slack/teams)",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pConvertPowerPointToPdf",
      "Prompt": "Convert PPT files to PDF before Distribution (true/false)",
      "Value": "",
      "Type": "String"
    },
    {
      "Name": "pTlsSecurity",
      "Prompt": "Supported Tls security modes used to connect to Reportworq",
      "Value": "Tls11,Tls12",
      "Type": "String"
    },
    {
      "Name": "pLogLevel",
      "Prompt": "Optional Reportworq job log level (Debug/Trace)",
      "Value": "",
      "Type": "String"
    }
  ]
}