SOAP API — Prevent closing a project with an open issue
function test_prevent_project_close_with_open_issue() {
var project_stage_id = NSOA.form.getValue('project_stage_id');
if (project_stage_id != 4) // if new stage is not closed, skip check
return;
//Read request
var issue = new NSOA.record.oaIssue();
issue.project_id = NSOA.form.getValue('id');
issue.issue_stage_id = 1;
var readRequest = {
type : "Issue",
method : "equal to", // return only records that match search criteria
fields : "id, date", // specify fields to be returned
attributes : [ // Limit attribute is required; type is Attribute
{
name : "limit",
value : "10"
}
],
objects : [ // One object with search criteria; type implied by rr 'type'
issue
]
};
var arrayOfreadResult = NSOA.wsapi.read(readRequest);
if (!arrayOfreadResult || !arrayOfreadResult[0])
NSOA.form.error('', "Internal error analyzing project. Contact account administrator.");
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.");
}
);
}
See also: