On a Sales Order, there is a custom Contact field....
# ask-stanley-ai
v
On a Sales Order, there is a custom Contact field. When a customer is selected, this field shows only the contacts related to that customer. When a user selects a contact from this field, I want the Ship To Address on the Sales Order to be populated automatically using the selected contact’s address. Important: The address should be used only on the transaction and must not be saved or added to the customer’s address book.
c
AI generated answer (using internal Slack threads):
To achieve this, you will need to use SuiteScript to create a custom field and a script to populate the 'Ship To Address' on the Sales Order based on the selected contact's address. Here's a high-level overview of how you can do this: 1. Create a custom field on the Sales Order record that will hold the selected contact's address. This field should be a free-form text field since the address will be a string. 2. Write a SuiteScript that triggers on field change. This script should be set to trigger when the custom 'Contact' field on the Sales Order is changed. 3. In the script, use the API to retrieve the selected contact's address. You can do this by loading the contact record using the internal ID from the changed field, and then getting the value of the address field. 4. Once you have the address, set the value of the custom 'Ship To Address' field on the Sales Order to this address. Here's a basic example of what the SuiteScript might look like:
Copy code
javascript
function fieldChanged(context) {
    if (context.fieldId === 'custbody_contact') {
        var contactId = context.currentRecord.getValue({
            fieldId: 'custbody_contact'
        });

        var contactRecord = record.load({
            type: record.Type.CONTACT,
            id: contactId
        });

        var contactAddress = contactRecord.getValue({
            fieldId: 'defaultaddress'
        });

        context.currentRecord.setValue({
            fieldId: 'shipaddress',
            value: contactAddress
        });
    }
}
This script will ensure that the 'Ship To Address' on the Sales Order is populated with the selected contact's address whenever a contact is selected. The address will only be used on the transaction and will not be saved or added to the customer’s address book. ****** 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.856567502
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85546881
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846618652
Please provide your feedback on this answer.