How do i trigger a confirmation modal when a recor...
# ask-stanley-ai
i
How do i trigger a confirmation modal when a record is deleted
c
AI generated answer (using internal Slack threads):
To trigger a confirmation modal when a record is deleted, you can use a combination of User Event and Client scripts in NetSuite. Here's a general approach: 1. User Event Script: Use a User Event script to hide the native delete button on the record form. This can be done in the
beforeLoad
function of the User Event script. 2. Client Script: Create a custom delete button using a Client script that will be displayed on the record form. This button, when clicked, will trigger a confirmation modal. If the user confirms the action, the record will be deleted. Here's a simplified example of how the Client script might look:
Copy code
javascript
function pageInit(scriptContext) {
    var currentRecord = scriptContext.currentRecord;
    var form = currentRecord.getField({fieldId: 'customform'});
    form.addButton({
        id: 'custpage_delete',
        label: 'Delete',
        functionName: 'confirmDelete'
    });
}

function confirmDelete() {
    var answer = confirm("Are you sure you want to delete this record?");
    if (answer) {
        var recordId = nlapiGetRecordId();
        nlapiDeleteRecord(nlapiGetRecordType(), recordId);
    }
}
In this script,
pageInit
function is used to add a custom delete button to the form. The
confirmDelete
function is called when this button is clicked. It displays a confirmation dialog, and if the user confirms, the record is deleted. ****** 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.811628282
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.801905513
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.797234535
Please provide your feedback on this answer.