How can I update a custom field a sales order afte...
# ask-stanley-ai
s
How can I update a custom field a sales order after a drop ship PO has been created from that sales order?
c
AI generated answer (using internal Slack threads):
To update a custom field on a sales order after a drop ship Purchase Order (PO) has been created from that sales order, you can use SuiteScript. Here's a general approach: 1. Create a User Event script that triggers on the creation of a drop ship PO. This script will be responsible for updating the custom field on the related sales order. 2. In the User Event script, use the
record
module to load the related sales order. You can get the internal ID of the related sales order from the created drop ship PO. 3. Once you have loaded the sales order, use the
setValue
method to update the custom field. Here's a sample script:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record'], function(record) {
    function afterSubmit(context) {
        if (context.type !== context.UserEventType.CREATE) {
            return;
        }

        var po = context.newRecord;
        var soId = po.getValue('createdfrom'); // assuming 'createdfrom' is the field linking the PO to the SO

        var so = record.load({
            type: record.Type.SALES_ORDER,
            id: soId
        });

        so.setValue('custbody_my_custom_field', 'New Value'); // replace 'custbody_my_custom_field' with your custom field ID and 'New Value' with the value you want to set

        so.save();
    }

    return {
        afterSubmit: afterSubmit
    };
});
Please replace
'custbody_my_custom_field'
with your actual custom field ID and
'New Value'
with the value you want to set. ****** 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.856525123
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85433948
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85018003
Please provide your feedback on this answer.