Jira Code: CN-6
This script is for auto-filling resource allocation of the project with all resources from the sales centre and employee centre on the creation of project task
User Event Script: CN-6 JJ UE Resource Allocate
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:C2 NATIVE
* CN-6
* Project Page Customization
* **************************************************************************
* Date : 30-08-2018
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is for autofilling resource allocation of project with all resources from sales centre and employee centre on the creation of project task
* Date created : 30-08-2018
*
* REVISION HISTORY
*
* Revision 1.0 ${date} nd : created
*
*
******************************************************************************/
define(['N/record','N/search'],
function(record,search) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type
* @Since 2015.2
*/
function afterSubmit(scriptContext) {
try{
if(scriptContext.type == 'create'){
var employeeSearchObj = search.create({
type: "employee",
filters:
[
["role.centertype","anyof","EMPLOYEE","SALESCENTER"]
],
columns:
[
search.createColumn({
name: "internalid",
summary: "GROUP",
label: "Internal ID"
})
]
});
var searchResult = employeeSearchObj.run().getRange({
start:0,
end:100
});
var n = searchResult.length;
for(var i=0;i<n;i++){
var singleResult = searchResult[i];
var internalId = singleResult.getValue({
name: "internalid",
summary: "GROUP"
});
if(internalId != 699){
var allocRecord = record.create({
type: record.Type.RESOURCE_ALLOCATION,
isDynamic: true
});
allocRecord.setValue({
fieldId: 'allocationresource',
value: internalId
});
allocRecord.setValue({
fieldId: 'project',
value: scriptContext.newRecord.id
});
allocRecord.setValue({
fieldId: 'allocationamount',
value: 1
});
allocRecord.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
}
}
}
}catch(e){
log.error('error',e)
}
}
return {
afterSubmit: afterSubmit
};
});