Jira Code: MR-156
When the phone call is created by the sales rep partner role the value of the employee category needs to update.
Last phone call
- If the user’s employee category is Inside sales the date value in the phone call record is updated on the LAST PHONE CALL DATE BY SALE field
- If the user’s employee category is Inside support the date value in the phone call record is updated on the LAST PHONE CALL DATE BY SUPPORT field
- If the user’s employee category is ‘other’ the date value in the phone call record is updated on the LAST PHONE CALL DATE field
/**
* @NApiVersion 2.x
* @NScriptType workflowactionscript
*/
/**
* Script Description: Last Phone call update
*/
/*******************************************************************************
* *MEGATEL *
* **************************************************************************
* Date:9/2/18
* Script name: MR-139 JJ WF Copy Last phone call date
* Script id: customscript484
* Deployment id: customdeploy1
* Applied to: Phone call
*
******************************************************************************/
define(['N/record', 'N/search', 'N/runtime'],
function(record, search, runtime) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @Since 2016.1
*/
function onAction(scriptContext) {
try {
log.debug({
title: 'scriptContext',
details: scriptContext
});
var employeecategory = runtime.getCurrentScript().getParameter("custscript1");
log.debug("employeecategory", employeecategory)
var objRecord = scriptContext.newRecord;
var company = objRecord.getValue({
fieldId: 'company'
});
var startdate = objRecord.getValue({
fieldId: 'startdate'
});
var completeddate = objRecord.getValue({
fieldId: 'completeddate'
});
var nluser = objRecord.getValue({
fieldId: 'nluser'
});
log.debug('nluser', nluser)
if (completeddate == "" || completeddate == null) {
completeddate = startdate
}
if (employeecategory == null || employeecategory == undefined || employeecategory == "") {
//search to find the sales rep partner user
var partnerSearchObj = search.create({
type: "partner",
filters: [
["internalid", "anyof", nluser]
],
columns: [
search.createColumn({
name: "custentity41",
label: "Employee Category"
})
]
});
var partnerObjsearchResult = partnerSearchObj.run().getRange({
start: 0,
end: 1000
});
log.debug('partnerObjsearchResult', partnerObjsearchResult)
for (var i = 0; i < partnerObjsearchResult.length; i++) {
var partnerempcat = partnerObjsearchResult[i].getValue({
name: "custentity41"
});
}
log.debug('partnerempcat', partnerempcat)
if (partnerempcat == 2) {
var pid = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_jj_lastcall_sale': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
} else if (partnerempcat == 1) {
var pid = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_jj_lastcall_support': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
} else {
var pid = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_mr_139_lastcalldate': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
} else if (employeecategory == 2) {
var id = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_jj_lastcall_sale': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
} else if (employeecategory == 1) {
var id = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_jj_lastcall_support': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
} else {
log.debug('last else')
var id = record.submitFields({
type: record.Type.CUSTOMER,
id: company,
values: {
'custentity_mr_139_lastcalldate': completeddate,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
} catch (e) {
log.debug({
title: e.name,
details: e.message
});
}
}
return {
onAction: onAction
};
});