Can any1 tell me why the following code is not wor...
# suitescript
r
Can any1 tell me why the following code is not working when I am trying to disable a field. I can disable it with client script that I know of, but is there any1 without using a client script?
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */

define(['N/ui/serverWidget'], (serverWidget) => {
	const onRequest = (context) => {
		var form = serverWidget.createForm({
			title: 'My Form'
		})
		var field = form.addField({
			id: 'custpage_customer',
			type: 'text',
			label: 'Customer'
		})
		field.updateDisplayType({
			displayType: serverWidget.FieldDisplayType.DISABLED
		})
		// field.isDisabled = true
		context.response.writePage(form)
	}

	return { onRequest }
})
https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4332670964.html#bridgehead_4332705065
a
That code is perfectly valid, try using the ENUM for the field type:
Copy code
serverWidget.FieldType.TEXT
n
I have had that behave inconsistently for me and sometimes using "disabled" works where the enum does not (on update display type). I cannot explain why, and it's definitely not "best practice" but humour me and try it.
r
Thanks @alien4u worked
🙌🏻 1
@NElliott will start using enums only from now on, find it very strange as well.
n
Yeah always use enums. If you use the NS plugin in WebStorm you can look through the different modules via the External Libraries folder and in there find the various enums if you want to confirm something 🙂 (See the image)
💯 2
r
One more thing I got to know was if i setDefault value in the same line in which I am creating the field updateDisplayType throws an error.
Copy code
var field = (form.addField({
	id: 'custpage_customer',
	type: serverWidget.FieldType.TEXT,
	label: 'Customer'
}).defaultValue = 'xyz')
field.updateDisplayType({
	displayType: serverWidget.FieldDisplayType.DISABLED
})
I have to specifically do
Copy code
var field = form.addField({
	id: 'custpage_customer',
	type: serverWidget.FieldType.TEXT,
	label: 'Customer'
})
field.defaultValue = 'xyz'
field.updateDisplayType({
	displayType: serverWidget.FieldDisplayType.DISABLED
})
e
That makes sense; the former is assigning
'xyz'
to
field
a
You can do .updateDisplayType({ with fluent coding, but not defaultValue