Friday, May 17, 2019

Invalid Form Element Name Error thrown when trying to add a Field to a Sublist during BeforeLoad event

Considering the scenario in which a custom field is added to a child record sublist by the beforeLoad function of an User Event script, when the parent record is loaded in Edit mode, the following SSS_INVALID_FORM_ELEMENT_NAME SuiteScript error might occur:

Notice (SuiteScript)

You have entered an invalid form element name. It must be prefixed with "custpage", unique, lowercase, and cannot contain any non-alphanumeric characters (except for the underscore character) in order to be added to the form or sublist.

The beforeLoad script used to get the sublist and add the field is the following:

		function userEventBeforeLoad(type, form, request)		{		if (type == 'edit')			{			var subList = form.getSubList('recmachcustrecord123');			subList.addField('custpage_test', 'text', 'Test Field');			}		}		

The name of the element complies with the restrictions indicated by the error message, but the field cannot be added. The reason behind this is the type of the sublist.

If the setting Allow Child Record Editing is not checked on the child record setup page, then the list is returned as a static list. This can be observed either in the SuiteScript Debugger by pausing the execution after getting the sublist and inspecting the sublist object or by adding the following log statement after getting the sublist and before adding the field:

		nlapiLogExecution('DEBUG', 'Sublist type', subList.getType());		
If Allow Child Record Editing is not checked, then the list is returned with the type staticlist, which stands for a read-only list. More information about sublist types can be found here.

After checking Allow Child Record Editing the sublist is returned with the type inlineeditor and the field is successfully added.

No comments:

Post a Comment