Set Field Value from Suitelet Popup Called from Client Script

A client side script on a transaction record calls a popup Suitelet that lets you search and select an item. After selecting the item from the Suitelet, it should then set the item to the line item of the transaction record.

You may use the javascript method window.opener to set value from the suitelet to the transaction record where it was called.

Client Script Calling the Suitelet popup:

* @NApiVersion 2.x
 * @NScriptType Suitelet
 */
define(['N/ui/serverWidget'], function(serverWidget) {‌
    function onRequest(context) {‌
		if (context.request.method === 'GET') {‌
			var myForm = serverWidget.createForm({‌
				title: 'Find Item(s)',
				hideNavBar: true
			});
			// In SuiteScript 2.0, file path of the script is being supplied
			myForm.clientScripModulePath = 'SuiteScripts/findItem.js';
			myForm.addField({‌
				id: 'custpage_selectitem',
				label: 'Select Item',
				type: serverWidget.FieldType.SELECT,
				source: 'item'
			});
			myForm.addSubmitButton({‌
				label: 'Submit'
			});
			context.response.writePage({‌
				pageObject: myForm
			});
		}
		else {‌
			var selecteditem = context.request.parameters.custpage_selectitem;
			var str = '';
			str += 'window.opener.nlapiSetCurrentLineItemValue("item","item"';
			str += ',"' + selecteditem + '");';
';
			context.response.write({‌
				output: str
			});
		}
    }

    return {‌
        onRequest: onRequest
    };
});

Leave a comment

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