how can I know in a User Event Script attached to ...
# ask-stanley-ai
l
how can I know in a User Event Script attached to a sales order is the SO is transformed into a cash sales through the UI? I need this script to be attached to the Sales Order Record.
c
AI generated answer (using internal Slack threads):
In a User Event Script attached to a Sales Order, you can determine if the Sales Order has been 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 (createdFrom) {
        var salesOrderRecord = record.load({
            type: record.Type.SALES_ORDER,
            id: createdFrom
        });

        if (salesOrderRecord) {
            // The Cash Sale was created from a Sales Order
            log.debug('Sales Order ID', createdFrom);
        }
    }
}
In this script, the 'afterSubmit' function is triggered after a record is submitted. It checks if the event type is 'CREATE', meaning a new record has been created. If so, it gets the value of the 'createdfrom' field from the new record. If this field is not empty, it means the Cash Sale was created from a Sales Order. The script then loads the Sales Order record using the internal ID obtained from the 'createdfrom' field and logs the Sales Order 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. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.867976427
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.853002369
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.848713577
Please provide your feedback on this answer.