NetSuite Development Notes
Wednesday, April 3, 2019
SuiteScript > Suitelet that Searches the Child Matrix Items Based on the Parent Item
Here's a sample Suitelet script that searches the child matrix item based on the 'Item ID' of the parent item:
>
function searchMatrixItem(request,response) {if (request.getMethod() == 'GET') { form = nlapiCreateForm('Search Matrix Items'); itemId = form.addField('custpage_itemid','text','Enter Item: ', 'item', null); submitButton = form.addSubmitButton('Submit'); response.writePage(form);}else {nlapiLogExecution('DEBUG','Searching the item', 'Searching..');itemId = request.getParameter('custpage_itemid');//Get the item idsearchItem = nlapiSearchRecord('inventoryitem',null,[new nlobjSearchFilter('itemid',null,'is',itemId)],null);itemId = searchItem[0].getId();//Search the child item var filters = new Array(); filters.push(new nlobjSearchFilter('matrixchild',null,'is','T')); filters.push(new nlobjSearchFilter('parent',null,'anyof',itemId)); var searchCols = new Array(); searchCols.push(new nlobjSearchColumn('itemid')); searchCols.push(new nlobjSearchColumn('baseprice')); var searchChItem = nlapiSearchRecord('inventoryitem',null,filters,searchCols); if (searchChItem) { response.write('<html> <table border="0"> <tr><th> Item ID: </th>' + '<th> Base Price: </th></tr>'); for (var x=0; x < searchChItem.length; x++) { resItemId = searchChItem[x].getValue('itemid'); resBasePrice = searchChItem[x].getValue('baseprice'); response.write('<tr><td>'+ resItemId +'</td>' + '<td>' + resBasePrice + '</td></tr><table>'); } response.write('<a href = "/app/site/hosting/scriptlet.nl?script=233&deploy=1">Back</a><html>'); } else { response.write('No child matrix items found. <br> <a href = "/app/site/hosting/scriptlet.nl?script=233&deploy=1">Back</a><html>'); }}}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment