Portlet Script Question: Can anyone tell why the c...
# general
j
Portlet Script Question: Can anyone tell why the code below returns null for the variables defined in the "for loop"? The output populates the portlet with the columns and if I change the code by defining a discrete var in either the "for loop" or the "row" definition, that variable is passed to the output. log.debug shows that var i in the "for loop" is returning 9 rows, which is what the saved search returns when it is run independently. log.debug for the variables in the "for loop" shows all are null. Any help is appreciated. Thanks, John /** * @NApiVersion 2.x * @NScriptType Portlet */ define(['N/search'], function(search) { function render(params) { var portlet = params.portlet; portlet.title = "MicroFab Select Inventory List"; portlet.addColumn({ id: 'pcpartno', type: 'TEXT', label: 'Part Number', align: 'LEFT', }); portlet.addColumn({ id: 'pcdesc', type: 'TEXT', label: 'Description', align: 'LEFT' }); portlet.addColumn({ id: 'pcloc', type: 'TEXT', label: 'Location', align: 'LEFT' }); portlet.addColumn({ id: 'pcbin', type: 'TEXT', label: 'Bin Number', align: 'LEFT' }); portlet.addColumn({ id: 'pconhand', type: 'FLOAT', label: 'On Hand', align: 'LEFT' }); var itemSearch = search.load({ id: 'customsearch930' }); var searchResult = itemSearch.run().getRange({ start: 0, end: 25 }); for(var i=0; i<searchResult.length;i++){ var piItem = (searchResult[i].getText({name: 'Name'})); var piDesc = (searchResult[i].getText({name:'Description'})); var piLoc = (searchResult[i].getText({name:'Bin On Hand : Location'})); var piBin = (searchResult[i].getText({name:'Bin On Hand : Bin Number'})); var piOnhand = (searchResult[i].getValue({name:'Bin On Hand : On Hand'})); //log.debug below returns piItemnull //log.debug({ // title: 'Debug Entry', // details: 'piItem' + piItem // }); portlet.addRow({ row: {pcpartno : piItem, pcdesc : piDesc, pcloc : piLoc, pcbin : piBin, pconhand : piOnhand} }); } } return { render: render }; });
b
probably better asked in #C29HQS63G
but generally use getValue for things like name, description (not sure about bin number)
and the parameters to getText or getValue should match that used when creating a column object
notably, the name parameter is the internal id of the column, not the text label
instead of
Copy code
var piItem   = (searchResult[i].getText({name: 'Name'}));
use
Copy code
var piItem   = searchResult[i].getValue({name: 'itemid'});
j
Bear with me; I am as "green" as it gets with SuiteScript. I think I have the get.Text matched with the column object and have used the internal id of the column object. As far as the var piItem, 'Name' is the field returned by the saved search - isn't that what should be used? Appreciate the feedback and what is the best way to correct my error in posting this in #C298P0BCK?
b
its too late, your ugly code is posted for all of general to see
that said, there is a difference between the internal id of a column, and its label
j
School of "hard knocks" 🤔
to see a general listing of columns
for example, if you search for itemid in the Search Columns section, the internal id is
itemid
and the label is
Name
you can programatically get at the columns for your search using something like itemSearch.columns so you can log what the column parameters look like (https://system.na0.netsuite.com/app/help/helpcenter.nl?fid=section_456374450683.html)
j
OK, guess I am confused...when creating the saved search, the fields selected were; 'Name', 'Bin On Hand : Location', etc... I think I see what you mean and will check the Record Browser to get the internal ids for the fields returned in the search.
Will check out the export tool as well --thanks!
@battk The chrome search export is very helpful. I finally got the portlet to display data by adding join and summary options parameters in the for loop variables.
Copy code
var piItem   = searchResult[i].getValue({name:'itemid', summary:'GROUP'});
Copy code
var piLoc    = searchResult[i].getValue({name:'location',join:'binonhand', summary:'GROUP'});
I have been trying to get the output to display the names instead of the internal ids for location and binnumber. I found the SuiteAnswers below, but I still have not been able to figure this out. Can I get there from how I approached this with a saved search? https://netsuite.custhelp.com/app/answers/detail/a_id/65117/kw/search%20returns%20internal%20id%20instead%20of%20name https://netsuite.custhelp.com/app/answers/detail/a_id/46602/kw/display%20name%20instead%20of%20internal%20id
b
Use getText instead of getValue
j
That was too easy - thanks!