--- title: "ExecuteStoredScript" slug: "executestoredscript" updated: 2024-07-23T10:22:25Z published: 2024-07-23T10:22:26Z canonical: "docs.datajet.app/executestoredscript" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # ExecuteStoredScript 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** | Key | Value(s) | Description | | --- | --- | --- | | method | ExecuteStoredScript | | | 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", }** | | debug | true/false | Optional. Default = false. If true, details of variables that were passed to the script will be output in the script log: ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/image-1684491662687.png) | | 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](/v1/docs/trackscript) and [GetScriptResult](/v1/docs/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. | | aSynchRequest | true/false | Added 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) | | onThread | true/false | Added 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) | | forceCore | true/false | Optional. Default = false If true, will look to local script storage rather than [ScriptHub](/v1/docs/script-hub-overview) | ```json { "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](/v1/docs/trackscript). ```json 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**) : ```json 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: ```json { "method": "ExecuteStoredScript", "aSyncRequest": true, "scriptId":"1234hajsj328ed" "projectName": "", "name": "Demonstration Populated Load", "targetProject": "", "project": "Demonstration" } ``` ## Related - [DEFINES](/defines.md) - [HOW TO - Use Variables effectively in scripts](/how-to-use-variables-effectively-in-scripts.md) - [System Variables](/system-variables.md)