ExecuteStoredScript
  • 2 Minutes to read
  • Dark
    Light
  • PDF

ExecuteStoredScript

  • Dark
    Light
  • PDF

Article summary

Executes a script that has been stored by name on the DataJet server.

NOTE: To add a script to the DataJet Server, use Script Editor | File | Push and enter the name under which the script is be stored.   To retrieve a stored script from the server, use Script Editor | File | Pull

KeyValue(s)Description
methodExecuteStoredScript
project"currentprojectname"Project name that is calling the Stored Script - automatically modified by Script Editor to equal Current Project - any value in here will be overwritten at run time.
For this particular call, "project" has no effect.
projectname"sourceprojectname"The name of the server project in which the script is stored 
  • each stored script is kept in a project 
  • the same stored script can be added to multiple projects - the copies of the script are not connected to each other, so changes must be applied to all copies of the script
  • scripts can be accessed from projects other than the project in which they are stored
name"scriptname"The name of the script, as it is stored on the server.
In this instance the following would be executed:
  • [sourceprojectname: scriptname]
targetProject"targetprojectname"Optional.  The name of the project that the stored script modifies.  If not provided, projectname is used.
NOTE:  If calling ExecuteStoredScript by doing "Run Selected" in Script Editor, targetProject must match the current project or the "Project Has Changed instance" error will be returned. 
variables{
"%variable1%": "value1",
"%variable2%": "value2",
}
If the Stored Script has a defines section and makes use of variables, the variables can be passed via ExecuteStoredScript.
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",
}

debugtrue/falseOptional.  Default = false.  If true, details of variables that were passed to the script will be output in the script log:
realm"realmname"By default the current realm will be assumed.   Use "global" to access scripts in the global realm.
scriptId"scriptId"ID (alphanumeric), provided by executing program, used in conjunction with TrackScript and GetScriptResult to monitor progress on a script.
If scriptId is not provided, DataJet server will automatically allocate a scriptid. 
authToken"authorisedToken"Only required for remote execution.
Authenticated token, as returned from DJ access server.
aSynchRequesttrue/falseAdded in v5.7.18
Allows asynchronous execution of stored scripts within DataJet Desktop- i.e., ExecuteStoredScript will return immediately rather than waiting for stored 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., ExecuteStoredScript will return immediately rather than waiting for stored script to finish executing.   (Use TrackScript to track status of an executing script)
forceCoretrue/falseOptional.  Default = false
If true, will look to local script storage rather than ScriptHub


{
  "method": "ExecuteStoredScript",
  "projectName": "SharedLibrary",
  "name": "MyStoredScript",
  "debug": true,
  "targetProject": "ProjectToBeModified",
  "variables": {
    "%Variable1%": "value1"
  },
  "project": "CurrentProject"
}


The following is an example of a remote script execution using REST API.  Note that a valid authorisation token is required.  To monitor script status, see TrackScript.

curl 
--location 'http://107.152.36.49:5555' \
--header 'Content-Type: application/json' \
--data '{
  "method": "ExecuteStoredScript",
  "projectName": "SharedLibrary",
  "name": "MyStoredScript",
  "debug": true,
  "targetProject": "ProjectToBeModified",
  "variables": {
    "%Variable1%": "value1"
  },
  "project": "CurrentProject"
  "authToken":"%AuthTokenHere%"
}'

The following will execute the script asynchronously using REST API (note "onThread":true) :

curl 
--location 'http://107.152.36.49:5555' \
--header 'Content-Type: application/json' \
--data '{
  "method": "ExecuteStoredScript",
  "projectName": "SharedLibrary",
  "name": "MyStoredScript",
  "debug": true,
  "targetProject": "ProjectToBeModified",
  "variables": {
    "%Variable1%": "value1"
  },
  "project": "CurrentProject"
  "onThread": true
  "authToken":"%AuthTokenHere%"
}'

The following will execute the script asynchronously from within explorer:

{
  "method": "ExecuteStoredScript",
  "aSyncRequest": true,
  "scriptId":"1234hajsj328ed"
  "projectName": "",
  "name": "Demonstration Populated Load",
  "targetProject": "",
  "project": "Demonstration"
}

Was this article helpful?

What's Next