Dynamically Source the UOM List into a Suitelet Select Field

Scenario

User wants a Suitelet to have a Select field sourcing the Unit Of measure List from another field. In this scenario, the list is being retrieved from the Inventory record.

Solution

function onRequest(context) {
    	if(context.request.method == 'GET'){
    		var myForm = serverWidget.createForm({
    			title: 'SuiteletForm'
    		});
    	
	        var myList = form.addField({
                        id: 'custpage_mylist',
                        label: 'Unit Of Measure',
                        type: serverWidget.FieldType.SELECT
                });
                var calendarEvent = record.create({
                        type: record.Type.INVENTORY_ITEM,
                        isDynamic: true
                });
                var fldEntity = calendarEvent.getField('unitstype');
                var entityData = fldEntity.getSelectOptions();
                myList.addSelectOption({
                        value: '',
                        text: ''
                })
                for (var i = 0; i < entityData.length; i++){
                        var entityValues = entityData[i];
                        myList.addSelectOption({
                        value : entityValues.value,
                        text : entityValues.text
                 });
                }
    		context.response.writePage(myForm);
    	}
    }

    return {
        onRequest: onRequest
    };

Leave a comment

Your email address will not be published. Required fields are marked *