-1

new to SuiteScript and Javascript in general. Working on one of the trainings to disable a field if another is checked (or enable) and have the following function below. I am getting an error though stating an unexpected error occured in a script running on this page. JS_Exception ReferenceError context is not defined. I am using Eclipse IDE with the NetSuite plug in so am using the template.

function fieldChanged(Context) {
        var customer = context.newRecord
        var applyCoupon = customer.getValue('custentity_sdr_apply_coupon');
        var couponCode = customer.getValue('custentity_sdr_coupon_code');
        //if apply coupon is checked enable coupon code, if unchecked disable coupon code and erase its content
        if (!applyCoupon) {couponCode.isDisabled = true;
        } else {couponCode.isDisabled = false;
        }

    }

2 Answers2

1

JavaScript identifiers are case-sensitive.

You have 'Context' as function parameter but you're using 'context' when accessing it.

function fieldChanged(context) {
    var customer = context.newRecord;
    ...
}
Jala
  • 889
  • 4
  • 9
0

Use currentRecord instead of newRecord.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 23 '21 at 12:33
  • 1
    Please add some explanation to your code. – Muhammedogz Sep 24 '21 at 00:50
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/29901335) – node_modules Sep 24 '21 at 12:04
  • @Variable: It offers an answer. But it’d be a lot more useful with more explanation. That’s a potential reason to downvote it, but not to delete it. – Jeremy Caney Sep 25 '21 at 01:42