On Project Start Script Automation

Executing Automation on Project Start

Note: Automation On Project Start is an advanced feature and may not be available for your system. For more information, please contact your administrator.

BLUE allows you to execute an automation script when starting a project, which could be used to validate project data or perform some other automation, such as copying sub-process custom field values to project-level custom fields.

When validating data, the project will start if the validation is successful. However, if the validation fails, the project remains in draft and the user sees a configurable error message. The ability to validate data is useful because it allows the system to verify that data has been entered correctly prior to starting the project. For example, you could have a script that verifies the project naming structure, or attribute values prior to start.

On “Create Process Template,” there is an optional On Project Start Script field. Once it is configured, the automation will occur for all new projects created with that template when the project owner attempts to start the project.

Who can use the On Project Start Script?

Administrators. The configuration of the script is defined on the process templates by an administrator. These templates are then used by project creators when creating a new project. The script defines the automation script that will be executed when starting the project.

Project Owners. The project owner will click the Start button when the project is ready to begin. Upon trying to start the project, the system will execute the automation script.

How do I set up an on project start script?

As an administrator, you will be able to add a script that will be executed on project start when creating or editing a process template. See process templates for more information on creating a process template. On the “Create Process Template” screen, locate the “On Project Start Script (JS)” field and enter the script that will be used.

Sample On Project Start Scripts

Example 1

var validationFailed = false;

if(subprocesses != null)
{
for(i in subprocesses)
{
var subprocessTask = subprocesses[i];
var subprocessId = subprocessTask.getId();
var aspgFile = subprocessTask.getGeneratedFromLibraryItem();
if(subprocessTask.getCustomFieldValue(“ComponentId”) == null || subprocessTask.getCustomFieldValue(“ComponentId”).trim().equals(“”) ||
subprocessTask.getName().endsWith(“(” + subprocessId + “)”) == false || subprocessTask.getCustomFieldValue(“ComponentCode”) == null ||
subprocessTask.getCustomFieldValue(“ComponentCode”).equalsIgnoreCase(aspgFile.getCustomFieldValue(“ComponentCode”)) == false )
{
validationFailed = true;
break;
}
}
}

if(validationFailed)
{
response.setStatus(false);
response.setResponseMessage(“Unable to start the project. All component metadata not yet generated automatically.
To re-trigger data collection please Edit project and add comment in the Project Description field. Upon save the data collection should retrigger”);
}
else
{
response.setStatus(true);
response.setResponseMessage(“All component metadata generated.”);
}

Example 2

var validationFailed = false;

if(project != null)
{
if(project.getCustomFieldValue(“A_114”) == null || project.getCustomFieldValue(“A_114”).trim().equals(“”))
{
validationFailed = true;
}
}

if(validationFailed)
{
response.setStatus(false);
response.setResponseMessage(“Unable to start the project. Component Number field is empty.”);
}
else
{
response.setStatus(true);
response.setResponseMessage(“All required metadata have values.”);
}

Note: Only the below objects are available from project start

“project”: Instance of ProjectCommand. Automation script can use this object to get and set project data.
“subprocesses”: A list of TaskCommand instances representing the project’s top-level subprocesses. Automation script can use these objects to get and set subprocess data.
“response”: Instance of AutomationNodeResponseCommand. Automation script can set the response status (success: true, failure: false) and response message on this object.
“restClient”: Instance of RestClient. Automation script can use this object to access REST services.
“admin”: Instance of CustomFieldAdmin. Stores the custom field administration information.