Script is not setting external id on account recor...
# ask-stanley-ai
t
Script is not setting external id on account record in afterSubmit, what am I missing, I am trying on an existing record
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like you are trying to set the
externalid
field in the
beforeSubmit
event. However, the
externalid
field cannot be set in the
beforeSubmit
event. This is because the
beforeSubmit
event occurs before the record has been saved, and any modifications to the record in this event can cause a record modification error since the original is now out of sync. Instead, you should set the
externalid
field in the
afterSubmit
event. Here is a sample code snippet:
Copy code
javascript
define(['N/record', 'N/log'],
function(record, log) {
    function afterSubmit(context){
      var itemRecord = context.newRecord;
      var itemField = itemRecord.getValue({ fieldId: 'cust_field_reference_i_triple_checked_is_correct'});
      
      if(itemField){
          record.submitFields({
              type: record.Type.NON_INVENTORY_ITEM,
              id: itemRecord.id,
              values: {
                  externalid: itemField
              }
          });
          log.audit({title: 'Set External ID of ' + itemRecord});
      }
    }

    return {
        afterSubmit: afterSubmit
    };
});
In this code, the
externalid
field is set in the
afterSubmit
event using the
submitFields
method. The
externalid
is set to the value of the custom field
cust_field_reference_i_triple_checked_is_correct
. ****** 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.860393584
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.858570158
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856984735
Please provide your feedback on this answer.
t
Sometimes, I can be so dumb 😞