Using SuiteScript and pop-up Suitelet, it is possible to add custom button on Sales Order form which would allow dynamically filtered selection of Item. Here is a brief description of such implementation:
1) Create a new Custom Transaction Body Field
a) Open Setup > Customization > Transaction Body Fields > New
b) Label = Custom Button; ID = _custombutton; Type = Inline HTML
c) Under Applies To > check Sale
d) Under Display > select Subtab = Items
e) Under Validating & Defaulting > Set Default Value to:
2) Create User Event script that will create custom button when Sales Order form is in create or edit mode
a) Open Setup > Customization > Scripts > New
b) Select User Event
c) Choose Name and ID
d) In Scripts, select script number 1 (User Event) - its code is below
e) Before Load Function = userEventBeforeLoad
f) Save
g) click Deploy Script
h) Applies To = Sales Order
i) Save
3) Create Suitelet Script with the selection pop-up window
a) Open Setup > Customization > Scripts > New
b) Select Suitelet
c) Choose Name and ID
d) In Scripts, select script number 2 (Suitelet) - its code is below
e) Function = suitelet
f) Save
g) Click Deploy Script
h) Save
4) Create Client Script which creates the pop-up window and handles its callback
a) Open Setup > Customization > Scripts > New
b) Select Client
c) Choose Name and ID
d) In Scripts, select script number 3 (Client Script) - its code is below
f) Save
5) Create or Edit any Sales Order record. A new button should now appear in Items subtab. After clicking that button, users will be given a choice to select from a filtered list of Items and the selected Item will be added on the Sales Order.
Example scripts:
Script 1 (User Event):
Script 2 (Suitelet):
function suitelet(request, response){
if(request.getMethod() == 'GET') {
// When the form is loaded
var form = nlapiCreateForm('Add Filtered Item');
form.addSubmitButton('Submit');
// Create Item Select field
var itemfield = form.addField('custpage_item', 'select', 'Item');
// Search for matching items; in this example we are looking for Items with department ID = 11; add these Items to Item Select Field
var search = nlapiSearchRecord('item', null, [new nlobjSearchFilter('department', null, 'anyOf', ['11'])], [new nlobjSearchColumn('itemid')]);
for (result in search){
itemfield.addSelectOption(search[result].id, search[result].getValue('itemid'));
}
// Write output
response.writePage(form);
} else {
// When the form is submitted
// Get selected Item ID
var data = request.getParameter('custpage_item');
// trigger the callback function and close pop-up window
response.write('<html><body><script>window.opener.addItemButtonCallback("' + data + '"); window.close();</script></body></html>');
}
}
Script 3 (Client Script):
Disclaimer: The sample code described herein is provided on an"as is" basis, without warranty of any kind, to the fullest extentpermitted by law. NetSuite Inc. does not warrant or guarantee the individualsuccess developers may have in implementing the sample code on theirdevelopment platforms or in using their own Web server configurations.
NetSuite Inc.does not warrant, guarantee or make any representations regarding the use,results of use, accuracy, timeliness or completeness of any data or informationrelating to the sample code. NetSuite Inc. disclaims all warranties, express orimplied, and in particular, disclaims all warranties of merchantability,fitness for a particular purpose, and warranties related to the code, or anyservice or software related thereto.
NetSuite Inc. shall not be liablefor any direct, indirect or consequential damages or costs of any type arisingout of any action taken by you or others related to the sample code.
No comments:
Post a Comment