What's wrong with this? ```const beforeSubmit: Ent...
# ask-stanley-ai
d
What's wrong with this?
Copy code
const beforeSubmit: EntryPoints.UserEvent.beforeSubmit = (context) => {
    const rec = context.newRecord;

    // Get the "name" value (standard for most custom records)
    const nameValue = rec.getValue({ fieldId: 'name' }) as string;

    if (nameValue) {
        // Copy into the "externalid" field
        rec.setValue({
            fieldId: 'externalid',
            value: nameValue,
            ignoreFieldChange: true
        });
    }
};
c
AI generated answer (using internal Slack threads):
The issue with the first code snippet is that the user is trying to link a custom record to a field on a time entry using
setValue
in a
beforeSubmit
context. However, the value is not being saved. This is likely because the custom record has not been fully saved and committed to the database at the time of the
beforeSubmit
event. The
beforeSubmit
event is triggered before the record is saved to the database, so any changes made to the record during this event are not yet committed. The user should move this logic to the
afterSubmit
event, which is triggered after the record has been saved to the database. In the second code snippet, the user is trying to modify a custom field in a
beforeSubmit
event. The changes are not being saved on the item. The issue was that the field was set to view only, which prevented the script from modifying it. In the third code snippet, the user is trying to set the
externalid
field to the value of another field on the record in a
beforeSubmit
event. However, this is not possible because the
externalid
field cannot be set in a
beforeSubmit
event. The
externalid
field is a system field that is used to uniquely identify a record for integrations and it can only be set or changed in an
afterSubmit
event. The user should move this logic to the
afterSubmit
event.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.866210938
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85937506
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.857666
Please provide your feedback on this answer.