Created
February 21, 2014 03:00
-
-
Save 23maverick23/9128015 to your computer and use it in GitHub Desktop.
NSOA: Create issue from change order task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Create a project issue for a change order task if one | |
* isn't already created. | |
* | |
* Version Date Author Remarks | |
* 1.00 20 Feb 2014 Ryan Morrissey | |
* | |
*/ | |
function createChangeOrderIssue(type) { | |
try { | |
// add all field names and value constants here | |
var TASK_TASKTYPEID = '4', | |
ISSUE_STAGEID = '1', | |
ISSUE_TYPEID = '4', | |
ISSUE_STATUSID = '1', | |
ISSUE_SOURCEID = '5', | |
ISSUE_SEVERITYID = '3', | |
// project task fields | |
FLD_TASK_TASKTYPEID = 'projecttask_typeid', | |
FLD_TASK_PROJID = 'projectid', | |
FLD_TASK_CUSTID = 'customerid', | |
FLD_TASK_ID = 'id', | |
// project task change order custom fields | |
FLD_CO_NUMBER = 'projecttask_changeorder_number__c', | |
FLD_CO_AMOUNT = 'projecttask_changeorder_amount__c', | |
FLD_CO_DATE = 'projecttask_changeorder_date__c', | |
FLD_CO_ISSUEID = 'projecttask_changeorder_issueid__c', | |
// issue fields | |
FLD_ISS_DESC = 'description', | |
FLD_ISS_OWNERID = 'owner_id', | |
FLD_ISS_PROJID = 'project_id', | |
FLD_ISS_CUSTID = 'customer_id', | |
FLD_ISS_TASKID = 'project_task_id', | |
FLD_ISS_TYPEID = 'issue_category_id', | |
FLD_ISS_SEVERITYID = 'issue_severity_id', | |
FLD_ISS_STATUSID = 'issue_status_id', | |
FLD_ISS_STAGEID = 'issue_stage_id', | |
FLD_ISS_SOURCEID = 'issue_source_id', | |
FLD_ISS_DATE = 'date'; | |
// get updated task record fields | |
var updTask = NSOA.form.getNewRecord(); | |
// if type == change order && issueid isblank, create issue | |
if (updTask[FLD_TASK_TASKTYPEID] == TASK_TASKTYPEID && !updTask[FLD_CO_ISSUEID]) { | |
// get current user information | |
var user = NSOA.wsapi.whoami(); | |
// create issue object for storing values | |
var recIssue = new NSOA.record.oaIssue(); | |
recIssue[FLD_ISS_DESC] = 'Change order #' + | |
updTask[FLD_CO_NUMBER] + ' (' + | |
updTask[FLD_CO_AMOUNT] + ')'; | |
recIssue[FLD_ISS_OWNERID] = user.id; | |
recIssue[FLD_ISS_PROJID] = updTask[FLD_TASK_PROJID]; | |
recIssue[FLD_ISS_CUSTID] = updTask[FLD_TASK_CUSTID]; | |
recIssue[FLD_ISS_TASKID] = updTask[FLD_TASK_ID]; | |
recIssue[FLD_ISS_DATE] = updTask[FLD_CO_DATE]; | |
recIssue[FLD_ISS_TYPEID] = ISSUE_TYPEID; | |
recIssue[FLD_ISS_STATUSID] = ISSUE_STATUSID; | |
recIssue[FLD_ISS_STAGEID] = ISSUE_STAGEID; | |
recIssue[FLD_ISS_SOURCEID] = ISSUE_SOURCEID; | |
recIssue[FLD_ISS_SEVERITYID] = ISSUE_SEVERITYID; | |
// disable the current user's filter set while script runs | |
NSOA.wsapi.disableFilterSet(true); | |
// add the new issue to the project | |
var issueResults = NSOA.wsapi.add( | |
[recIssue] | |
); | |
if (issueResults && !issueResults[0].errors) { | |
// new project task object | |
var recTask = new NSOA.record.oaProjecttask(updTask[FLD_TASK_ID]); | |
recTask[FLD_CO_ISSUEID] = issueResults[0].id; | |
// disable the current user's filter set while script runs | |
NSOA.wsapi.disableFilterSet(true); | |
// enable custom field editing | |
var update_custom = { | |
name: 'update_custom', | |
value: '1' | |
}; | |
// update the task to add linked issue internal id | |
var taskResults = NSOA.wsapi.modify( | |
[update_custom], | |
[recTask] | |
); | |
} else { | |
NSOA.meta.log('error', 'Issue was not created.'); | |
return; | |
} | |
} | |
} catch(e) { | |
NSOA.meta.log('error', 'Try/catch error: ' + e); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment