SOAP API — Post a Project Discussion Message
The following code sample posts a message automatically to the project discussion for the project when the project stage for that project is changed on the project form. You can create a project form script, paste this code sample in the scripting studio editor, select After Save
as the event triggering the script to run, and main
as the entrance function.

function main(type) {
if (type == 'edit') {
try {
var current_stage_id = NSOA.form.getOldRecord().project_stageid;
var new_stage_id = NSOA.form.getValue('project_stage_id');
if ("" + current_stage_id == "" + new_stage_id) {
return;
}
var stage_name = (new NSOA.record.oaProjectstage(new_stage_id)).name;
var msg = new NSOA.record.oaThreadedMessage();
msg.table_name = "project";
msg.record_id = NSOA.form.getValue('id');
msg.content = "Project stage has been updated to: " + stage_name;
NSOA.wsapi.add([msg]);
}
catch(err) {
NSOA.meta.log('error', err.message);
}
}
}
See also:
-
SOAP API object reference for ThreadedMessage