James Morris
11/25/2024, 7:43 PMCeligo AI
11/25/2024, 7:43 PMAI generated answer (using internal Slack threads):Based on the conversations, it seems that you can't unset an external ID once it's set, but you can update it. You can set the external ID using SuiteScript, but not in a beforeSubmit user event script due to performance reasons. Instead, you can do it in an afterSubmit user event script. Here is a sample SuiteScript 2.0 server script that updates the external ID of vendor payment records to a timestamp string upon record creation, only if the external ID field is empty:
javascript
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*/
define(['N/record'], function(record) {
function afterSubmit(context) {
if (context.type !== context.UserEventType.CREATE) {
return;
}
var newRecord = context.newRecord;
var externalId = newRecord.getValue('externalid');
if (!externalId) {
var timestamp = new Date().getTime();
record.submitFields({
type: record.Type.VENDOR_PAYMENT,
id: newRecord.id,
values: {
externalid: 'timestamp_' + timestamp
}
});
}
}
return {
afterSubmit: afterSubmit
};
});
This script uses the N/record
module to update the external ID field of the vendor payment record. It first checks if the context type is CREATE
, meaning the record is being created. If the external ID field is empty, it generates a timestamp, prepends it with 'timestamp_', and sets this as the new external ID.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
11/25/2024, 7:43 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825121045
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822936535
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.817287862
Celigo AI
11/25/2024, 7:43 PM