pen one
05/21/2024, 2:03 PMfunction disableFieldIfNotUser36(record, lineIndex) {
var userId = runtime.getCurrentUser().id;
log.debug({title: 'Current User ID', details: userId});
if (userId == '36') return;
var field = record.getSublistField({
sublistId: 'recmachcustrecord230',
fieldId: 'custrecord235',
line: lineIndex
});
field.isDisabled = true;
}
function disableFieldsForExistingLines(record) {
try {
var lineCount = record.getLineCount({
sublistId: 'recmachcustrecord230'
});
for (var i = 0; i < lineCount; i++) {
disableFieldIfNotUser36(record, i);
}
} catch (error) {
log.debug({ title: 'Catch Error', details: error });
}
}
function disableLineField(scriptContext) {
try {
var currentRecord = scriptContext.currentRecord;
var sublistId = scriptContext.sublistId;
if (sublistId !== 'recmachcustrecord230') return;
var userId = runtime.getCurrentUser().id;
log.debug({title: 'Current User ID', details: userId});
if (userId == '36') return;
var selectedLine = currentRecord.getCurrentSublistIndex({
sublistId: 'recmachcustrecord230'
});
disableFieldIfNotUser36(currentRecord, selectedLine);
} catch (error) {
log.debug({ title: 'Catch Error', details: error });
}
}
function validateLineField(scriptContext) {
try {
var currentRecord = scriptContext.currentRecord;
var sublistId = scriptContext.sublistId;
if (sublistId !== 'recmachcustrecord230') return true;
var userId = runtime.getCurrentUser().id;
log.debug({title: 'Current User ID', details: userId});
if (userId == '36') return true;
var lineCount = currentRecord.getLineCount({
sublistId: 'recmachcustrecord230'
});
if (lineCount === 0) {
// No line items exist, disable the field for the new line being created
var newLineIndex = currentRecord.getCurrentSublistIndex({
sublistId: 'recmachcustrecord230'
});
disableFieldIfNotUser36(currentRecord, newLineIndex);
} else {
// Disable the field for the existing line being edited
var selectedLine = currentRecord.getCurrentSublistIndex({
sublistId: 'recmachcustrecord230'
});
disableFieldIfNotUser36(currentRecord, selectedLine);
}
return true;
} catch (error) {
log.debug({ title: 'Catch Error', details: error });
return true;
}
}
erictgrubaugh
05/21/2024, 3:34 PMpageInit
and/or lineInit
as wellbattk
05/21/2024, 5:03 PM