/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
/************************************************************************************
HGLPA - 222 Set SO ID in TASK
************************************************************************************
*
* Author: Jobin & Jismi IT Services LLP
*
* Date Created : 19th-September-2022
*
* Description : Set SO ID in TASK
*
* REVISION HISTORY
*
***********************************************************************************/
define(['N/record'],
/**
* @param{record} record
*/
(record) => {
/**
* Defines the function definition that is executed after record is submitted.
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {Record} scriptContext.oldRecord - Old record
* @param {string} scriptContext.type - Trigger type; use values from the context.UserEventType enum
* @since 2015.2
*/
const afterSubmit = (scriptContext) => {
try{
if (scriptContext.type === 'create'){
let currentRec = scriptContext.newRecord;
log.debug("currentRec",currentRec);
let soID = currentRec.id;
let companyID = currentRec.getValue({
fieldId:'entity'
});
let taskId = currentRec.getValue({
fieldId:'custbody_jj_task_name'
});
if(!taskId)
return false;
let taskData = record.load({
type: record.Type.TASK,
id: taskId
// isDynamic: true
});
let company = taskData.getValue({
fieldId:'company'
});
if(companyID === company ){
log.debug("loop")
let taskSo = taskData.setValue({
fieldId: 'transaction',
value: soID,
});
log.debug("taskSo",taskSo)
taskData.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
}
}
}
catch(err)
{
log.debug("error@afterSubmit",err)
}
}
return {afterSubmit}
});