penone
penone

Reputation: 792

Suitescript 2.0 - How to show a field and update value based on dropdown?

I have a drop down that, when a particular option is selected a hidden field will be displayed and that field which have a new value. I am able to get the field to display but am not able to populate the field with the value. Script below:

           function fieldChanged(context) {
                var records = context.currentRecord;
                if (context.fieldId == 'custbody_data') {
                    var note = context.currentRecord.getField({ fieldId: 'custbody_note' });

                    var type = records.getValue({
                        fieldId: 'custbody_data'
                    });

                    if (type == "2") {
                        note.isDisplay = true;
                        note.setValue = "test";

                    } else if (type == "1") {
                       note.isDisplay = false;
                       note.setValue = "";
                    }
                }
            }

return {
fieldChanged: fieldChanged
}

Upvotes: 0

Views: 7284

Answers (1)

michoel
michoel

Reputation: 3783

note.setValue = "";

There are two problems in what you are trying to do:

  1. With the NetSuite API, to manipulate the value of fields in the record you need to use the N/currentRecord#Record object , not the N/currentRecord#Field. In other words you need to be calling context.currentRecord.setValue().

  2. setValue is a method, not a property. I.e. you need to call the function setValue() with the new value, and not assign it a value (note.setValue = "new value") like you are attempting.

Putting those together, the correct syntax for updating a field value is:

context.currentRecord.setValue({
  fieldId: 'custbody_note',
  value: "test",
});

Upvotes: 3

Related Questions