automation_nation10
08/19/2024, 3:04 PMerictgrubaugh
08/19/2024, 3:43 PMautomation_nation10
08/19/2024, 4:08 PM/**
* @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
};
});
erictgrubaugh
08/19/2024, 8:17 PMpurchaseorders
sublist on the Vendor Bill.automation_nation10
08/20/2024, 2:11 AMStefan Reeder
09/21/2024, 4:50 AMlet 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
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"})
]
})