how can I know in a User Event Script if a sales O...
# ask-stanley-ai
l
how can I know in a User Event Script if a sales Order is transformed into a cash sales through the UI?
c
AI generated answer (using internal Slack threads):
In a User Event Script, you can determine if a Sales Order is transformed into a Cash Sale through the UI by checking the
createdfrom
field on the Cash Sale record. This field will contain the internal ID of the Sales Order from which the Cash Sale was created. Here is a sample code snippet that demonstrates this:
Copy code
javascript
function afterSubmit(context) {
    if (context.type !== context.UserEventType.CREATE)
        return;

    var newRecord = context.newRecord;
    var createdFrom = newRecord.getValue('createdfrom');

    if (newRecord.type === 'cashsale' && createdFrom) {
        var salesOrder = record.load({
            type: record.Type.SALES_ORDER,
            id: createdFrom
        });

        // Perform your logic here
    }
}
In this code,
context.newRecord
is the Cash Sale record that was just created. The
createdfrom
field of this record is checked to see if it exists. If it does, it means that the Cash Sale was created from a Sales Order. The Sales Order is then loaded using the
record.load
function and the internal ID of the Sales Order (
createdFrom
). ****** 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.867358
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846305609
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843019
Please provide your feedback on this answer.