This script is supposedly updating a custom field ...
# suitescript
l
This script is supposedly updating a custom field on the Invoice by copying its value from the Amount Paid standard field whenever a Customer Payment is saved (or after it is saved). However, I have no luck. Tried a lot of variations. None of them worked. Any help would be greatly appreciated. Thank you.
b
share error messages / logs
l
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "SSS_MISSING_REQD_ARGUMENT",
  "message": "load: Missing a required argument: id",
  "stack": [
    "createError(N/error)",
    "afterSubmit(/SuiteScripts/paidOrNot.js:31)",
    "createError(N/error)"
  ],
  "cause": {
    "name": "SSS_MISSING_REQD_ARGUMENT",
    "message": "load: Missing a required argument: id"
  },
  "id": "",
  "notifyOff": false,
  "userFacing": true
}
It's logging the count and the isApplied although it says false.
b
compare the opening and closing brace of your if statement
l
message has been deleted
It's working now. Thanks! I also changed the submitFields to just setValue
b
beware, saving records in a loop like that can be very bad for performance
r
The error you got.it's because of in submitFields function you passed wrong arg. You need to replace 'invId' from invId.
l
@battk yup, anyway, we typically receive payments for at most 2 invoices only and we don't have much in open invoices per customer. Regardless, what's the best alternative here? To have it scheduled instead? Thank you.
@Ramanand Dubey thanks for that one
b
doesnt really matter the number, the basic estimate is that updating 1 invoice will double the submit time
2 invoices would triple
it gets out of hand quickly
if you dont care and can wait, then you should at least try to make the submitFields work, its faster
ideally a map reduce or scheduled script would be the script doing the work
the time paid for record saves is done later asynchronously
if the amount paid must happen synchronously, you can keep the user event, but i would recommend logic to only save records when the amount paid actually changes. dont do it every time the user event is triggered
i would also recommend having a plan for partial payments, you probably do not want that field changing values if there are 2 payments for 1 invoice
if you go the scheduled or map/reduce route, take a look into using the amount paid column for the invoice
netsuite automatically calculates how much of an invoice has been paid, and takes into account things like multiple payments or payments via other transactions like credit memos