Client needs to populate the value at line level. In order to avoid the value overwriting when sourcing, populated value after sourcing.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record', 'N/search'],
/**
* @param{record} record
* @param{search} search
*/
function(record, search) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
//var blendedType=1;
function pageInit(scriptContext) {
try{
var project= scriptContext.currentRecord.getValue({fieldId: 'company'});
}
catch(e){
console.error("error@PageInit",e)
}
}
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
}
/**
* Function to be executed when field is slaved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
*
* @since 2015.2
*/
function postSourcing(scriptContext) {
try{
if(scriptContext.sublistId == 'assignee' && scriptContext.fieldId == 'resource'){
// console.log("working");
var project= scriptContext.currentRecord.getValue({fieldId: 'company'});
console.log("project",project);
var fieldLookUp = search.lookupFields({
type: 'job',
id: project,
columns: ['custentity_jj_prj_rate_type', 'custentity_jj_blended_rate']
});
console.log("values",fieldLookUp);
if(fieldLookUp['custentity_jj_prj_rate_type'][0].value==1){
console.log("RAYE",fieldLookUp['custentity_jj_blended_rate']);
scriptContext.currentRecord.setCurrentSublistValue({
sublistId: 'assignee',
fieldId: 'unitprice',
value: fieldLookUp['custentity_jj_blended_rate'],
});
}
}
return true;
}
catch(e){
console.error("error@fieldChange",e)
}
}
/**
* Function to be executed after sublist is inserted, removed, or edited.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @since 2015.2
*/
function sublistChanged(scriptContext) {
}
/**
* Function to be executed after line is selected.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @since 2015.2
*/
function lineInit(scriptContext) {
}
/**
* Validation function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @returns {boolean} Return true if field is valid
*
* @since 2015.2
*/
function validateField(scriptContext) {
}
/**
* Validation function to be executed when sublist line is committed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateLine(scriptContext) {
}
/**
* Validation function to be executed when sublist line is inserted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateInsert(scriptContext) {
}
/**
* Validation function to be executed when record is deleted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateDelete(scriptContext) {
}
/**
* Validation function to be executed when record is saved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @returns {boolean} Return true if record is valid
*
* @since 2015.2
*/
function saveRecord(scriptContext) {
}
return {
pageInit: pageInit,
//fieldChanged: fieldChanged,
postSourcing: postSourcing,
// sublistChanged: sublistChanged,
// lineInit: lineInit,
// validateField: validateField,
// validateLine: validateLine,
// validateInsert: validateInsert,
// validateDelete: validateDelete,
// saveRecord: saveRecord
};
});