has anyone tried using suitescript to get the poam...
# suitescript
a
has anyone tried using suitescript to get the poamount from a vendor bill? i am using the purchase order sub list and I’m able to get the po id, but not the poamount for some reason
e
You'll likely want to share code, but if I had to guess, you're referring to the Related Records list, which is not actually a sublist but a linked search. My guess is you'll need to use the ID you've retrieved to lookup the amount(s) from the related PO(s)
a
thanks. here is what i'm trying:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(['N/currentRecord', 'N/ui/message', 'N/log'], function(currentRecord, message, log) {

    function validateField(context) {
        var record = currentRecord.get();

        // Only trigger this for the 'total' field
        if (context.fieldId === 'total') {
            var billAmount = record.getValue('total');

            // Access the 'purchaseorders' sublist
            var poCount = record.getLineCount({ sublistId: 'purchaseorders' });

            if (poCount > 0) {
                for (var i = 0; i < poCount; i++) {
                    var poAmount = parseFloat(record.getSublistValue({
                        sublistId: 'purchaseorders',
                        fieldId: 'poamount',
                        line: i
                    }));

                    var allowedAmount = poAmount * 1.10;

                    log.debug('PO Amount', poAmount);
                    log.debug('Bill Amount', billAmount);
                    log.debug('Allowed Amount', allowedAmount);

                    if (billAmount > allowedAmount) {
                        // Show warning message on the form
                        message.create({
                            title: 'Warning',
                            message: 'The vendor bill exceeds the purchase order amount by more than 10%.',
                            type: message.Type.WARNING
                        }).show();

                        // Optionally, return false to prevent saving if the condition is not met
                        // return false;
                    }
                }
            }
        }

        // Allow the field change
        return true;
    }

    return {
        validateField: validateField
    };
});
e
Where are you finding field IDs for this sublist? According to the Records Browser, there is no
purchaseorders
sublist on the Vendor Bill.
a
thanks. i was looking at the xml under machine name=purchaseorders
s
What I've done previously is a Purchase Order search with the filter set to billingtransaction = your vendor bill id. Then you'll need to dig a bit deeper on the resulting Bill IDs and line totals to get the amounts you need to compare if there are multiple POs on the Bill. For performance (and to get around any permission issues) I tend to preload the data (ie.
let data={...}
) in a beforeLoad UE then create an inline html field with the defaultvalue being
<script>let data=${JSON.stringify(data)};</script>
which then makes your data object available for your client scripts even if the user does not have permission to search
Copy code
search.create({
   type: "purchaseorder",
   filters:
   [
      ["type","anyof","PurchOrd"], 
      "AND", 
      ["billingtransaction","anyof","1234"]
   ],
   columns:
   [
      search.createColumn({name: "billingtransaction", label: "Billing Transaction"}),
      search.createColumn({
         name: "internalid",
         join: "billingTransaction",
         label: "Vendor Bill ID"
      }),
      search.createColumn({name: "item", label: "Item"}),
      search.createColumn({name: "tranid", label: "Purchase Order"})
   ]
})
thankyou 1