I am receiving an error in my beforesubmit usereve...
# ask-stanley-ai
s
I am receiving an error in my beforesubmit userevent script of obj.commitLine is not a function - I want to add and save a new line to my sales order in this script. Why am I receiving this error and how can I fix that?
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** The error you're encountering is due to the fact that the
commitLine
function is not used on regular (non-dynamic) records. Also, the
newRecord
during
beforeSubmit
is not in dynamic mode. In a
beforeSubmit
User Event script, you only need to use
setSublistValue
on the next available line. You don't need to insert the line unless you actually want to insert a line at the first line. Here's an example of how you can add a new line to a sublist in a
beforeSubmit
User Event script:
Copy code
javascript
newRecord.setSublistValue({
    sublistId: 'salesteam',
    fieldId: 'employee',
    line: thenextline,
    value: 1
});
In this example,
thenextline
is the line count since it's zero indexed. Please note that for an
afterSubmit
User Event script, you need to load the record again and save it to make your changes. However, keep in mind that this is generally not a good practice as it will double your sales order save times.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.864911556
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.862662911
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.860925674
Please provide your feedback on this answer.