Anyone ever run into an error trying to load &...
# suitescript
s
Anyone ever run into an error trying to load & save an existing vendor (via script), and receive an error that the field id "isindividual" is not defined?
Copy code
require(['N/record'], function (record) {

let vendor = record.load({
	type: 'vendor',
	id: '10671',
	isDynamic: true
});
console.log('isindividual 1: ' + vendor.getValue('isindividual'));
vendor.setValue({
	fieldId: 'isindividual',
	value: 'Company'
});
console.log('isindividual 2: ' + vendor.getValue('isindividual'));
vendor.save({
	ignoreMandatoryFields: false,
	enableSourcing: true
});

})
It's very odd - every time I run the above script on the same record, "isindividual 1:" never outputs a value
Yet if I remove the lines that set the isindividual field, the script fails to save the vendor
Seems to be limited to a certain NS account
oh, I think it's due to the form making the type (company vs indiv) required
b
find the field in the ui, find its internal id
it is not isindividual
its represented in the ui as a radiobox, but its really a checkbox in suitescript
s
Ah ha - if you make the "Type" field required via the form, you can't load and save the record via script
without setting the isindividual field every single time
s
battk is is correct. Your code above is undefined behavior.
s
You can try it out, but if you create a custom form for a vendor, and set the native "Type" field to mandatory, it causes this behavior. The following script will error out if you try to run it.
Copy code
require(['N/record'], function (record) {

let vendor = record.load({
	type: 'vendor',
	id: '[YOUR VENDOR'S ID]',
	isDynamic: true
});
vendor.save({
	ignoreMandatoryFields: false,
	enableSourcing: true
});

})
And you'll get a script error saying that Type (pointing at isindividual) is not defined.
Seems like isindividual is more of a dynamic client-side field that NS adds to the page, probably to control if the vendor is a company or an individual. Via script I would have controlled this via isperson.
But when you make the Type field required, it seems like NS gets a little confused