Skip to main content

The Types of Scripts

There are two types of scripts you will write and run, based on where that script is going to be executed:

Client Scripts#

Client Scripts are often used when creating a web client using the Twinit React UI Framework.

These scripts must be ES Modules and must have a default export containing all the scripts you wish to use. You can have as many Client Scripts as you want, allowing you to organize your scripts any way you like.

Backend Scripts#

Backend Scripts are used by the Object Model API (OMAPI) Service, the Datasources Service, the Workflow Service, and other Twinit Services. These scripts must be vanilla JavaScript and must not contain any imports or exports. You can also have as many Backend Scripts as you want, allowing you to organize your scripts any way you like.

Both types of scripts can be run and tested using the Twinit IDE Extension, however it's important you create the correct type of script based on where you plan to execute it.

Often times you may have scripts that you only execute using the Twinit IDE extension. These could be Project setup scripts, debugging scripts, a migration script, or any other script which is not executed by a client or a backend service. In this case it is usually more convenient to use a Client Script (as we will do throughout this training).

Examples#

Client Script#

const SOME_VALUE = "Example Client Script"
let exampleScriptModule = {
   someValueScript(input, libraries, ctx, callback) {      return SOME_VALUE   },
   async useSomeValueScript(input, libraries, ctx, callback) {      return await doSomethingAsync(SOME_VALUE)   }
}
export default exampleScriptModule

Backend Script#

const SOME_VALUE = "Example Client Script"
function someValueScript(input, libraries, ctx, callback) {   return SOME_VALUE},
async function useSomeValueScript(input, libraries, ctx, callback) {   return await doSomethingAsync(SOME_VALUE)}

We will learn more about each type of script, how to write them, how to run them, and how to use them in later lessons.