Michael McNamara
02/08/2024, 7:00 PMfunction lineInit(context) {
try {
/** this will disable the amount for existing line */
var rec = context.currentRecord;
var itemCount = rec.getLineCount('item');
var sublistName = context.sublistId;
var line = rec.getCurrentSublistIndex({ sublistId: sublistName });
if (itemCount >= line) {
var theField = rec.getSublistField({
sublistId: sublistName,
fieldId: 'amount',
line: line
});
theField.isDisabled = true;
}
} catch (e) {
console.error(':octagonal_sign: lineInit', JSON.stringify(e, null, 4));
}
}
battk
02/08/2024, 7:12 PMbattk
02/08/2024, 7:14 PMMichael McNamara
02/08/2024, 7:42 PMMichael McNamara
02/08/2024, 7:43 PMbattk
02/08/2024, 7:44 PMMichael McNamara
02/08/2024, 7:45 PMMichael McNamara
02/08/2024, 11:27 PMfunction postSourcing(context) {
var myRec = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
var line = context.line;
if (sublistName === 'item' && sublistFieldName === 'item'){
var sublistObj = myRec.getSublist({
sublistId: 'item'
});
var columnObj = sublistObj.getColumn({
fieldId: 'amount'
});
//set
columnObj.isDisabled = true;
}
}
Michael McNamara
02/08/2024, 11:27 PMJeff Subat
02/15/2024, 2:27 PMMichael McNamara
02/15/2024, 4:38 PM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/record'],
/**
* @param{record} record
*/
function(record) {
/**
* 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
*/
function pageInit(context) {
var rec = context.currentRecord;
var sublistObj = rec.getSublist({
sublistId: 'item'
});
var columnObj = sublistObj.getColumn({
fieldId: 'amount'
});
//set
columnObj.isDisabled = true;
//get
var isDisabled = columnObj.isDisabled;
}
/**
* 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(context) {
}
/**
* 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(context) {
var myRec = context.currentRecord;
var sublistName = context.sublistId;
var sublistFieldName = context.fieldId;
var line = context.line;
if (sublistName === 'item' && sublistFieldName === 'item'){
var sublistObj = myRec.getSublist({
sublistId: 'item'
});
var columnObj = sublistObj.getColumn({
fieldId: 'amount'
});
//set
columnObj.isDisabled = true;
}
}
/**
* 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(context) {
try {
/** this will disable the amount for existing line */
var rec = context.currentRecord;
var itemCount = rec.getLineCount('item');
log.debug({
title: itemCount
});
var sublistName = context.sublistId;
var line = rec.getCurrentSublistIndex({ sublistId: sublistName });
if (itemCount >= 0 || itemCount == null) {
log.debug({
title: "line created"
})
var theField = rec.getSublistField({
sublistId: sublistName,
fieldId: 'amount',
line: line
});
log.debug({
title: "something"
});
theField.isDisabled = true;
}
} catch (e) {
console.error(':octagonal_sign: lineInit', JSON.stringify(e, null, 4));
}
}
/**
* 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 {
postSourcing: postSourcing,
lineInit: lineInit,
pageInit: pageInit
};
});