how to track external Id changes for old records
# ask-stanley-ai
n
how to track external Id changes for old records
c
AI generated answer (using internal Slack threads):
To track changes in the
externalId
of old records, you would need to create a script that logs the changes. This script would need to be triggered whenever a record is updated. Here's a basic example of how you could do this:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/log'], function(record, log) {
    function afterSubmit(context) {
        var newRecord = context.newRecord;
        var oldRecord = context.oldRecord;
        
        var newExternalId = newRecord.getValue('externalid');
        var oldExternalId = oldRecord.getValue('externalid');
        
        if (newExternalId !== oldExternalId) {
            log.audit({
                title: 'External ID changed',
                details: 'Record ' + newRecord.id + ' had its external ID changed from ' + oldExternalId + ' to ' + newExternalId
            });
        }
    }

    return {
        afterSubmit: afterSubmit
    };
});
This script logs an audit entry whenever the
externalId
of a record changes. You can then review these logs to track the changes. Please note that you can change the
externalId
of a record via script or REST API. However, you cannot unset the
externalId
once it has been set. You can only change it to a different value. ****** 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.821960568
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.812194824
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.810485899
Please provide your feedback on this answer.