ExecuteScript
  • 2 Minutes to read
  • Dark
    Light
  • PDF

ExecuteScript

  • Dark
    Light
  • PDF

Article summary

Executes an embedded DataJet JSON script or a DataJet JSON script file.

KeyValue(s)Description
method"ExecuteScript"Executes the provided script
project"CurrentProjectName"The name of the current project
script[][
{method1},
{method2},
{...}
]
If "script" is provided, "scriptfilename" is not required.   Either "script" or "scriptfilename" must be provided.
ignoreErrorstrue/falseDefault = false.   If true, will continue executing methods even after an error is encountered.
sampletrue/falseDefault = false.  If true, load methods such as CreateTableFromFile will load only a sample of data.  
See 
targetProject"NameOfProjectToModify"
scriptId"UserDefinedScriptID"Optional. The script ID to use to reference the script.    If not provided, an ID will be generated.  
Script Ids of executed scripts can be see in Desktop | Script | History
contacts[][
{email1@domain1},
{email2@domain2},
{...}
]
Optional.  List of contacts to send script result to by email.
scriptFilename"PathAndFileOfScript"If "scriptFilename" is provided, "script" is not required.   Either "script" or "scriptFilename" must be provided.
logFilename"PathandFileForLogData"Location of logfile.
filename"PathAndFileOfLogData"Deprecated.  If "filename" is provided, and no "logfilename" is provided, log data will be output to "filename" 
variables{}[
{"variable1":"value1"},
{"variable2":"value2"}
{...}
]
If the Stored Script has a defines section and makes use of variables, the variables can be passed via ExecuteScript.
In this example, the defines section of "scriptname" should contain %variable1% and %variable2%.
See DEFINES for more details.
Note that the variable key is not changed at run-time. So for example if the variable is defined in the following way in the defines section:

{      "key": "%myvariablename%",      "value": "myvalue"    }

...then...

{
"%myvariablename%": "%myvariablename%",
}


becomes the following at run-time:

{
"%myvariablename%": "myvalue",
}

debug
true/falseOptional. Default = false. If true, details of variables that were passed to the script will be output in the script log:
quiettrue/falseOptional.  Default = true.   If false, ScriptEditor will not log to Mongo.
aSynchRequesttrue/falseAdded in v5.7.18
Allows asynchronous execution of stored scripts within DataJet Desktop- i.e., ExecuteScript will return immediately rather than waiting for script to finish executing.   (Use TrackScript to track status of an executing script)
onThreadtrue/falseAdded in v5.7.24
Allows asynchronous execution of stored scripts from outside of Datajet Desktop - i.e., ExecuteScript will return immediately rather than waiting for script to finish executing.   (Use TrackScript to track status of an executing script)


The following is the blank JSON method:

{
  "method": "ExecuteScript",
  "project": "",
  "script": [
    {}
  ],
  "ignoreErrors": false,
  "sample": false,
  "targetProject": "",
  "scriptId": "",
  "contacts": [],
  "logFilename": "",
  "scriptFilename": "",
  "quiet": false,
  "debug": false,
  "variables": {}
}

The following shows a populated ExecuteScript method where script information is contained in the "script" element:

{
  "method": "ExecuteScript",
  "ignoreErrors": false,
  "sample": false,
  "scriptId": "",
  "script": [
    {
      "method": "DeleteField",
      "name": "cluster",
      "table": "customer",
      "project": "RegressionDB"
    },
    {
      "method": "DeleteFromCollection",
      "name": "MF Profile cluster",
      "type": "DJExplorer.MFProfileControl",
      "collection": "REPORTS",
      "project": "RegressionDB"
    },
    {
      "method": "Export",
      "exportHeaders": false,
      "urns": false,
      "quotedStringHeaders": true,
      "overwrite": true,
      "tabDelimited": true,
      "createImportScript": false,
      "fields": [
        "customer.age",
        "customer.income"
      ],
      "dataSet": {
        "logic": "or",
        "name": "SubSet",
        "strict": true,
        "set": [
          {
            "logic": "or",
            "stype": "TABLE",
            "entity": "customer"
          }
        ]
      },
      "exportFilename": "%DATAPATH%age_income.txt",
      "project": "RegressionDB"
    },
   
  ],
  "targetProject": "RegressionDB",
  "project": "RegressionDB"
}

This example will execute the script denoted by scriptFilename:

{
  "method": "ExecuteScript",
  "ignoreErrors": false,
  "script": [
    {
      "project": "BikeData2"
    }
  ],
  "sample": false,
  "scriptId": "",
  "scriptFilename": "%DATAPATH%TestExecuteScript_Child.json",
  "quiet": false,
  "debug": false,
  "project": "BikeData2",
  "targetProject": "BikeData2"
}



Was this article helpful?