I have programming/IT background, but I have never written in SuiteScript before. I understand triggers/events and built-in objects like "this". But I am new to SuiteScript version of those concepts.
My goal is to remind user that the customer of current invoice record (Invoice form) has a negative balance. The reason is, accounting department told me that they issue credit memos to paid invoices, and those credits stay there forever never to be used again because there is no obvious way of knowing if customer has any negative balance when they create a new invoice.
Based on examples and the object reference I came up with this. I want to pop up a message if the customer of the current invoice record has any negative balance. Am I on the right track? The invoice is usually created from the customer record, so I don't think customer_onChange trigger will be necessary. Thanks in advance.
/** * @NApiVersion 2.x * @NScriptType UserEventScript */ define(['N/record'], function (record) { function showErrorMessage(msgText) { var myMsg = msg.create({ title: "Negative Balance", message: msgText, type: msg.Type.ERROR }); myMsg.show({ duration: 5000 }); } function CheckBalance(context) { var invoiceRecord = context.currentRecord; var customerRecord = invoiceRecord.entity; if (customerRecord.balance < 0) { showErrorMessage("This customer has " + customerRecord.balance + " credit. Consider before accepting any full payments"); return false; } return true; } return { pageInit: CheckBalance, }; });