Is there a way to use suitescript to track when an...
# ask-stanley-ai
b
Is there a way to use suitescript to track when an item is removed from a record sublist? For example, removing a contact from a customer?
c
AI generated answer (using internal Slack threads):
Yes, you can use SuiteScript to track when an item is removed from a record sublist. For example, when a contact is removed from a customer record, you can use the
record.detach
method. This method detaches a record from another record. Here is an example of how you can use it:
Copy code
javascript
var record = require('N/record');
var myRecord = record.detach({
    record: {
        type: 'contact',
        id: '123'
    },
    from: {
        type: 'customer',
        id: '456'
    },
    subrecord: {
        field: 'sublistField',
        subrecord: 'subrecordField'
    }
});
In this example, the contact with id '123' is detached from the customer with id '456'. The
subrecord
object is optional and is used when the record is a subrecord of a sublist field. For tracking removed line items on Sales Order Transactions, you can use the client script event
validateDelete
. This event can be used to copy the line information to a custom field when a line is removed. You can also create a custom record to capture more information like who deleted the item, when it was deleted, what item was deleted, quantity, custom fields, etc. You can even prompt for a reason for deletion in a popup. Here is an example of how you can use the
validateDelete
method:
Copy code
javascript
function validateDelete(context) {
    var currentRecord = context.currentRecord;
    var sublistName = context.sublistId;
    var line = context.line;
    // get the information you need from the line
    var item = currentRecord.getSublistValue({
        sublistId: sublistName,
        fieldId: 'item',
        line: line
    });
    // prompt for a reason for deletion
    var reason = prompt('Why are you deleting this item?');
    // store the information in a custom record or field
    // ...
    return true;
}
In this example, when a line is deleted, the
validateDelete
function is called. It gets the item from the line that is being deleted and prompts for a reason for deletion. The information is then stored in a custom record or field. ****** 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.847977
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.8428334
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839866579
Please provide your feedback on this answer.