i have the below client scripts that disable a sub...
# suitescript
p
i have the below client scripts that disable a sublist column if a record already exists in that sublist. What I am wanting to do is have it also disable the column when a new record is being created and there are no other records present. If I create a new record when then are no lines it doe not disable the field until the line is saved - but all other items created after have that column disabled. Any idea on how can I get it to disable in first creation with 0 lines?
Copy code
function 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;
        }
    }
e
Run your disable logic on
pageInit
and/or
lineInit
as well
👍 1
b
in addition to pageInit, use Column.isDisabled instead,
👍 1