Auto select Purchase Contract when creating a Purc...
# ask-stanley-ai
m
Auto select Purchase Contract when creating a Purchase Order line
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are trying to auto-populate certain fields on a Purchase Order based on the selected Purchase Contract. This can be achieved using a client script in SuiteScript. Here is a sample code snippet that was shared in the conversations:
Copy code
javascript
define(['N/currentRecord', 'N/ui/dialog', 'N/log', 'N/record'], function(currentRecord, dialog, log, record) {
    @NApiVersion 2.0
    @NScriptType ClientScript

    function fieldChanged(context) {
        var po = context.currentRecord;
        if (context.fieldId == 'purchasecontract') {
            pcSelected = po.getValue({ fieldId: 'purchasecontract' });
            if (pcSelected !== null) {
                var newpc = po.getValue({ fieldId: 'purchasecontract' });
                var pc = record.load({
                    type: record.Type.PURCHASE_CONTRACT,
                    id: newpc
                });

                var pcitemType = pc.getValue('custbody_byu_po_item_type');
                var pcpoType = pc.getValue('custbody_byu_po_type');
                var subsidiary = pc.getValue('subsidiary');
                var location = pc.getValue('location');
                var fundSource = pc.getValue('custbody_byu_pc_funding_source');

                if (pcitemType) {
                    po.setValue({ fieldId: 'custbody_byu_po_item_type', value: pcitemType })
                }
                if (pcpoType) {
                    po.setValue({ fieldId: 'custbody_byu_po_type', value: pcpoType })
                }
                if (subsidiary) {
                    po.setValue({ fieldId: 'subsidiary', value: subsidiary })
                }
                if (location) {
                    po.setValue({ fieldId: 'location', value: location })
                }
                if (fundSource) {
                    po.setValue({ fieldId: 'custbody_byu_po_funding_source', value: fundSource })
                }

                dialog.alert({
                    title: 'Automation Warning',
                    message: 'Po Type,  Po Item Type, Subsidiary, Location, and Fund Source updated automatically based on Purchase Contract record selected.'
                });
            }
        }
        return true
    };

    return {
        fieldChanged: fieldChanged
    }
});
This script listens for changes to the 'purchasecontract' field on the Purchase Order record. When a Purchase Contract is selected, it loads the corresponding Purchase Contract record and retrieves the values of certain fields. It then sets the values of corresponding fields on the Purchase Order record. Please note that you may need to adjust the field IDs in the script to match the actual field IDs in your NetSuite account. ****** 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.821599126
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.805614
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.79803139
Please provide your feedback on this answer.