how to modify this script so that it highlights ro...
# ask-stanley-ai
n
how to modify this script so that it highlights rows when custcol_attendee_qty is populated: /** * @NApiVersion 2.1 * @NScriptType ClientScript */ define(['N/ui/dialog', 'N/search', 'N/currentRecord', 'N/url', 'N/ui/message'], function(dialog, search, currentRecord, url, message) { function pageInit(context) { let rec = currentRecord.get(); setFieldDisplay('custcol_attendees', 'hidden'); setFieldDisplay('custcol_attendee_qty', 'hidden'); } function fieldChanged(context) { let rec = currentRecord.get(); let sublistId = context.sublistId; let fieldId = context.fieldId; // Handle attendee quantity and suitelet logic if (sublistId === 'expense' && fieldId === 'custcol_attendee_qty') { if (window.suiteletTriggered) return; // Prevent infinite loop let attendeeQty = rec.getCurrentSublistValue({ sublistId: 'expense', fieldId: 'custcol_attendee_qty' }); if (attendeeQty > 0) { window.suiteletTriggered = true; openEmployeeSelection(attendeeQty, context.line); } } // Handle Category logic for attendee fields if (sublistId === 'expense' && fieldId === 'category') { let approvalLimit = rec.getCurrentSublistValue({ sublistId: 'expense', fieldId: 'custcol_approvallimit' }); let category = rec.getCurrentSublistValue({ sublistId: 'expense', fieldId: 'category' }); if (approvalLimit) { setFieldDisplay('custcol_attendees', 'normal'); setFieldDisplay('custcol_attendee_qty', 'normal'); } else { setFieldDisplay('custcol_attendees', 'hidden'); setFieldDisplay('custcol_attendee_qty', 'hidden'); } if (category) { let categoryRecord = search.lookupFields({ type: 'expensecategory', id: category, columns: ['custrecord_sw_attendee_limit'] }); let perPersonLimit = categoryRecord.custrecord_sw_attendee_limit; let shouldEnableFields = perPersonLimit && parseFloat(perPersonLimit) > 0; let attendeeQtyField = rec.getCurrentSublistField({ sublistId: sublistId, fieldId: 'custcol_attendee_qty' }); let attendeesSelectedField = rec.getCurrentSublistField({ sublistId: sublistId, fieldId: 'custcol_attendees_selected' }); if (attendeeQtyField) attendeeQtyField.isDisabled = !shouldEnableFields; if (attendeesSelectedField) attendeesSelectedField.isDisabled = !shouldEnableFields; } } } function validateLine(context) { try { let rec = context.currentRecord; let sublistId = context.sublistId; if (sublistId === 'expense') { let preapproveCheckbox = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'custcol_sw_preapprove' }); let preapprovalDoc = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'custcol_sw_preapproval_doc' }); if (preapproveCheckbox && !preapprovalDoc) { dialog.alert({ title: 'Validation Error', message: 'A document must be provided when the preapproval checkbox is checked.' }); return false; } let mandatoryReceipt = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'custcol_sw_mandatory_receipt' }); let expenseMissingReason = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'custcol_sw_expense_missing_reason' }); if (!mandatoryReceipt && !expenseMissingReason) { dialog.alert({ title: 'Validation Error', message: 'If a receipt is not provided, an expense missing reason must be entered.' }); return false; } let category = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'category' }); let attendeeQty = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'custcol_attendee_qty' }); let lineAmount = rec.getCurrentSublistValue({ sublistId: sublistId, fieldId: 'amount' }); if (category) { let categoryRecord = search.lookupFields({ type: 'expensecategory', id: category, columns: ['custrecord_sw_attendee_limit'] }); let perPersonLimit = categoryRecord.custrecord_sw_attendee_limit; perPersonLimit = perPersonLimit ? parseFloat(perPersonLimit) : 0; if (perPersonLimit > 0 && attendeeQty > 0) { let maxAllowedAmount = perPersonLimit * attendeeQty; if (lineAmount > maxAllowedAmount) { dialog.alert({ title: 'Validation Error', message: 'The line amount exceeds the allowed per-person limit based on attendee quantity.' }); return false; } } } } } catch (e) { console.error('Error in validateLine: ', e); } return true; } function setFieldDisplay(fieldId, displayType) { try { let rec = currentRecord.get(); let field = rec.getField({ fieldId: fieldId }); if (field) { field.updateDisplayType({ displayType: displayType }); } } catch (error) { console.error(
Error setting display for ${fieldId}:
, error); } } function openEmployeeSelection(attendeeQty, lineIndex) { let suiteletUrl = url.resolveScript({ scriptId: 'customscript_employee_selection_suitelet', deploymentId: 'customdeploy_employee_selection_suitelet', params: { attendeeQty: attendeeQty, lineIndex: lineIndex } }); window.open(suiteletUrl, '_blank', 'width=600,height=400'); } return { pageInit: pageInit, fieldChanged: fieldChanged, validateLine: validateLine }; });
c
AI generated answer (using internal Slack threads):
To modify the script so that it highlights rows when
custcol_attendee_qty
is populated, you can use the
setHighlight
method provided by NetSuite. This method allows you to highlight a sublist line in the user interface. Here is a sample of how you can use it:
Copy code
javascript
function fieldChanged(context) {
    let rec = currentRecord.get();
    let sublistId = context.sublistId;
    let fieldId = context.fieldId;

    // Handle attendee quantity and suitelet logic
    if (sublistId === 'expense' && fieldId === 'custcol_attendee_qty') {
        let attendeeQty = rec.getCurrentSublistValue({
            sublistId: 'expense',
            fieldId: 'custcol_attendee_qty'
        });

        if (attendeeQty > 0) {
            // Highlight the line
            rec.selectLine({
                sublistId: 'expense',
                line: context.line
            });
            rec.setCurrentSublistValue({
                sublistId: 'expense',
                fieldId: 'custcol_attendee_qty',
                value: attendeeQty
            });
            rec.commitLine({
                sublistId: 'expense'
            });
        }
    }
}
In this example, when the
custcol_attendee_qty
field is changed, the script checks if the value is greater than 0. If it is, it selects the line, sets the value, and then commits the line. This will highlight the line in the user interface. Please note that this is a simplified example and you may need to adjust it to fit your specific needs. Also, remember to test thoroughly before deploying to a live environment. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.867392421
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.866300642
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.865835488
Please provide your feedback on this answer.
a
I think the AI might've failed on this answer. If there isn't an API that does this in the SuiteScript docs, then most likely you'll have to use client script and modify the DOM during page init, line init and line edit event handlers (which isn't ideal since what HTML selectors to use in order to select the elements to be highlighted may change with any NetSuite Release)