Prevent closing a project that has open issues
This script prevents the closing of a project that has open issues.
-
Enforces workflow requirement that all open issues be addressed before a project can be closed
Follow the steps below or download the solutions file, see Creating Solutions for details.
Setup
-
Create two parameters, see Creating Parameters.
The List source for the ProjectClosedStage Pick List parameter is “Project stage”.
The List source for the IssueOpenStage Pick List parameter is “Stage”.
-
Create a new Project form script deployment.
-
Enter a Filename and click SAVE. The extension ‘.js’ is automatically appended if not supplied.
-
Click on the script link to launch the Scripting Studio.
-
(1) Copy the Program Listing below into the editor, (2) set the Before save event, and set test_prevent_project_close_with_open_issue as the Entrance Function.
Program Listing
// project_stage_id and issue_stage_id depend on account settings
function test_prevent_project_close_with_open_issue() {
// return if new stage is not closed
if (NSOA.form.getValue('project_stage_id') !=
NSOA.context.getParameter('ProjectClosedStage'))
return;
// Load issue data
var issue = new NSOA.record.oaIssue();
issue.project_id = NSOA.form.getValue('id');
issue.issue_stage_id = NSOA.context.getParameter('IssueOpenStage');
var readRequest = {
type: "Issue",
fields: "id, date",
method: "equal to",
objects: [issue],
attributes: [{
name: "limit",
value: "1"
}]
};
var arrayOfreadResult = NSOA.wsapi.read(readRequest);
if (!arrayOfreadResult || !arrayOfreadResult[0])
NSOA.form.error('', "Internal error analyzing project issues.");
else if (arrayOfreadResult[0].errors === null && arrayOfreadResult[0].objects)
arrayOfreadResult[0].objects.forEach(
function(o) {
NSOA.form.error('', "Can't close project with open issues.");
}
);
}