This topic contains 6 replies, has 0 voices, and was last updated by Duncan 8 years, 2 months ago.
-
AuthorPosts
-
September 19, 2016 at 4:02 pm #23527
DuncanI 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.
PHP Code:
/**
* @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,};
});
This is a cached copy. Click here to see the original post. -
September 19, 2016 at 4:40 pm #23528
torin@aminian.comI'm not familiar with scripts but this seems like something that can be done using an action in a workflow. The action would be show message and the condition would be a formula {entity.balance}<0.
-
September 19, 2016 at 10:52 pm #23529
k_duncCouldn't agree more with torin@aminian.com. A Workflow will quite sufficiently handle this task without having to do any coding.
-
September 20, 2016 at 1:57 am #23530
chanarbonSimilar to the provided solution coming from @torin.aminian.com, workflow should can address this concern with a simple Show Message.
But maybe you have another set of validations that you want. But here's some tips on the changes you need for your script to work properly. Also use invoiceRecord.getValue({"fieldId":"entity"}) instead of invoiceRecord.entity. You also need to load the customerRecord and then perform a getValue() to get the balance.
-
September 20, 2016 at 9:43 am #23531
erictgrubaughYou seem to be on the right track with your code. torin@aminian.com is also correct that this could alternatively be a pretty straight-forward Workflow.
The pageInit function doesn't return anything, so your two `return` statements are unnecessary. You are also missing the actual import of the N/ui/message module as `msg`. Other than that, I don't see anything glaring about your code. Did you have a more specific question? Or an error you're seeing?
-
September 20, 2016 at 10:26 am #23532
DuncanThank you for the answers. I am looking into "workflow" now as I am not sure what it is, but sounds less complicated. And I definitely prefer less complicated methods
-
September 20, 2016 at 2:53 pm #23533
DuncanThank you, @torin@aminian.com
Your solution did the trick (for the formula I just used the GUI). I showed it to our accounting, they were happy to see how simple it was. I think they might even manage it by themselves for any future WorkFlows similar to this.
-
AuthorPosts
You must be logged in to reply to this topic.