Skip to main content
Version: v4.5

IafScripts

Use the IafScript API to create and manage scripts and script versions on the platform.

create#

Creates scripts and returns an array of the created Script objects.

ParameterRequiredTypeDescription
scriptsYesArray<Script>Pass an array of Script objects to create.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Array<Script> - Returns an array of the created Script objects

Examples
const scripts = await IafScripts.create(scriptsArray);

createScript#

Creates an array of Script class objects and returns a Page object with the created Script objects.

ParameterRequiredTypeDescription
scriptsYesArray<Script>Pass an array of Script objects to create.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Page<Array<Script>> - Returns a Page object with the created Script objects

Examples
const createdScripts = await IafScripts.createScript(scriptsArray);

createVersion#

Creates a ScriptVersion class object.

ParameterRequiredTypeDescription
idYesStringPass the Script's id.
versionYesScriptVersionPass a ScriptVersion object with a "_userData" property and the script content as its value.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

ScriptVersion - The created ScriptVersion object

Examples
const version = { _userData: "<YOUR_SCRIPT_CONTENT_HERE>" };
const scriptVersion = await IafScripts.createVersion(id, version);

delete#

Deletes a Script class object from the Item Service.

ParameterRequiredTypeDescription
scriptYesScriptPass the Script object you want to delete.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

String - 204 response {ok:204}

Examples
const response = await IafScript.delete(script);

deleteVersion#

Deletes a ScriptVersion when you pass its id.

ParameterRequiredTypeDescription
idYesStringPass the Script's id.
versionIdYesStringPass the ScriptVersion's id.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

String - 204 response {ok:204}

Examples
const response = await IafScripts.deleteVersion(id, versionId);

getById#

Gets a Script when you pass its id.

ParameterRequiredTypeDescription
idYesStringThe Script's id
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Script - Returns the created Script object

Examples
const script = await IafScript.getById(id);

getByName#

Gets Scripts when you pass a name.

ParameterRequiredTypeDescription
nameYesStringPass the Script's "_name" property's value.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

Array<Script> - An array of Scripts that match the name you pass.

Examples
const scripts = await IafScripts.getByName("project_setup_script_3");

getScripts#

Gets scripts that match your query.

ParameterRequiredTypeDescription
criteriaYesNamedUserItemCriteriaPass a NamedUserItemCriteria object with your query.
ctxNoCtxContext, such as namespaces and authentication token information.
optionsYesItemSvcOptionsPass an ItemSvcOptions object with your response pagination options, such as "_page", "_project", "_offset", and "_sort".
Returns

Array<Script> - A Page object with an array of Scripts that match your query.

Examples
const criteria = { _usertype: "project_setup" };const options = { _project: "_userData" };
const setupScripts = await IafScript.getScriptsWithPagination(criteria, options);

getScriptsWithPagination#

Gets a Page of Script class objects that match your query.

ParameterRequiredTypeDescription
criteriaYesNamedUserItemCriteriaPass a NamedUserItemCriteria object with your query.
ctxNoCtxContext, such as namespaces and authentication token information.
optionsYesItemSvcOptionsPass an ItemSvcOptions object with your response pagination options, such as "_pageSize", "_project", "_offset", and "_sort".
Returns

Page<Array<Script>> - A Page object with an array of Scripts that match your query.

Examples
const criteria = { _usertype: "project_setup" };const options = { _project: "_userData" };
const setupScripts = await IafScript.getScriptsWithPagination(criteria, options);

getVersionById#

Gets a ScriptVersion when you pass its id.

ParameterRequiredTypeDescription
idYesStringPass the Script's id.
versionIdYesStringPass the ScriptVersion's id.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

ScriptVersion -

Examples
const scriptVersion = await IafScripts.getVersionById(id, versionId);

getVersions#

Gets a Script's versions.

ParameterRequiredTypeDescription
idYesStringPass the Script's id.
criteriaNoNamedUserItemVersionCriteriaPass a simple query to match the versions you want.
ctxNoCtxContext, such as namespaces and authentication token information.
optionsYesJSONPass an object with your response pagination options, such as "_page", "_project", "_offset", and "_sort".Pass an ItemSvcOptions object with your response pagination options, such as "_page", "_project", "_offset", and "_sort".
Returns

Array<ScriptVersion> - An array of ScriptVersion class objects.

Examples
const criteria = { createdDate : { "$gt" : "2016-04-09T08:28:47" }};
const versions = await IafScripts.getVersions(script._id, criteria);

isValid#

Checks if the script content for a Script class object is valid.

ParameterRequiredTypeDescription
scriptYesStringPass the script content you want to validate.
Returns

boolean - Returns true if the script content is valid.

Examples
const isValid = IafScripts.isValid(myScriptContent);

isValidJSCode#

Checks if a script's content is valid JavaScript.

ParameterRequiredTypeDescription
scriptYesStringPass the script content you want to validate.
Returns

boolean/object - Returns true if the JavaScript is valid. If the JavaScript is not valid, an ErrorObject returns.

Examples
const isValid = IafScripts.isValidJSCode(myScriptContent);

update#

Updates a Script object that already exits. To update a Script's content, use updateScriptVersion.

ParameterRequiredTypeDescription
scriptYesScriptPass the Script object with updated properties or values.
ctxNoctxContext, such as namespaces and authentication token information.
Returns

Script - The updated Script object

Examples
//Update scriptconst scriptObj = {  _id: "5c931fddb834740001251982",  _name: "Project setup script",  _shortName: "prjSetup",  _userType: "project_setup_script_updated"};
const script = await IafScripts.update(project,scriptObj,ctx);

updateVersion#

Updates the script content of a specific ScriptVersion.

ParameterRequiredTypeDescription
idYesStringPass the script's id.
versionYesScriptVersionPass a ScriptVersion object with a "_userData" property and the updated script content as its value.
ctxNoCtxContext, such as namespaces and authentication token information.
Returns

ScriptVersion - The updated ScriptVersion object

Examples
const version = { _userData: "<YOUR_SCRIPT_CONTENT_HERE> };
const updatedScriptVersion = await IafScripts.updateVersion(id, version);