I'm new to portlets, not to scripting.
Basically, I want a portlet that has 5 dropdowns (ultimately should be multiselect) and when I hit Submit, it runs a few searches (likely via Suitelet) and displays the results in the same portlet AND still shows those same dropdowns and the submit so I can resubmit without having to refresh the portlet or the page.
With a Simple Form portlet, it's easy enough to display the fields and the submit button as well as loading a first, default set of results from the search queries (these are put into a table that's loaded into an inline HTML field as part of the simple form. When I hit Submit, it calls a SuiteLet that runs the same query with the filters set on that form, and the Suitelet returns the results. However, the problem is my fields are gone now.
I hope there's a nuance I'm missing and this is possible. It's also possible what I've done is wonky overkill. I've included my code in case it helps for the problem at hand or folks see something wrong with my approach. I've also tried playing with a HTML portlet but am having trouble with targeting the portlet instead of loading the whole current page or a new tab/window.
Simple Form portlet javascript:
function execSupportOverviewPL(portlet) { portlet.setTitle('Support Statistics: Customer Effort, Case Volume, First Day Resolution'); //setting default values for the filters. Could be replaced with a lookup to a "saved settings" concept that keeps track of users' last (or saved) setting var periodType = 'quarter'; var startDate = '1/1/2015'; var endDate = ''; var product = 'All'; var team = 'All'; var source = 'All'; var periodField = portlet.addField('custpage_periodtype','select','Period Type'); periodField.addSelectOption('month','Monthly'); periodField.addSelectOption('quarter','Quarterly'); periodField.addSelectOption('year','Annually') periodField.addSelectOption('weekOfYear','Weekly'); periodField.setDefaultValue(periodType); var startDateField = portlet.addField('custpage_startdate','date','Date Range'); startDateField.setDefaultValue(startDate); var endDateField = portlet.addField('custpage_enddate','date','to'); endDateField.setDefaultValue(endDate); var productField = portlet.addField('custpage_product','select','Product'); productField.addSelectOption('All','-All-'); productField.addSelectOption('1','Product 1'); productField.addSelectOption('33','Product 2'); productField.setDefaultValue(product); var teamField = portlet.addField('custpage_team','select','Team'); teamField.addSelectOption('All','-All-'); teamField.addSelectOption('1','Analyst'); teamField.addSelectOption('2','Blue'); teamField.addSelectOption('3','Elite'); teamField.setDefaultValue(team); var sourceField = portlet.addField('custpage_source','select','Source'); sourceField.addSelectOption('All','-All-'); sourceField.addSelectOption('2','Phone'); sourceField.addSelectOption('-5','Web'); sourceField.addSelectOption('4','Chat'); sourceField.addSelectOption('1','Email'); sourceField.setDefaultValue(source); var mainHeaderRow = '<table class="text" cellpadding="5" cellspacing="1"><tbody><tr class="portletheadernosort"><td class="portletheadernosort" align="center"><b>Customer Effort Scores</b></td>'; var mainFooterRow = '</tr></tbody></table>'; var displayAllContent = mainHeaderRow + '<tr><td valign="top">' + getCESresults(periodType,startDate,endDate,product,team,source) + '</td></tr>' + mainFooterRow; var fld = portlet.addField('html','inlinehtml','My HTML'); fld.setLayoutType('normal','startcol'); fld.setDefaultValue(displayAllContent); portlet.setSubmitButton(nlapiResolveURL('SUITELET','customscript_execsupportoverviewsl','customdeploy_execsupportoverviewsl1'),'Submit'); } main Suitelet called from portlet function execSupportOverviewSL(request, response) { var startDate = request.getParameter('custpage_startdate'); var endDate = request.getParameter('custpage_enddate'); var periodType = request.getParameter('custpage_periodtype'); var product = request.getParameter('custpage_product'); var team = request.getParameter('custpage_team'); var source = request.getParameter('custpage_source'); var mainHeaderRow = '<table class="text" cellpadding="5" cellspacing="1"><tbody><tr class="portletheadernosort"><td class="portletheadernosort" align="center"><b>Customer Effort Scores</b></td><td class="portletheadernosort" align="center"><b>Cases Created</b></td>'; var mainFooterRow = '</tr></tbody></table>'; var displayAllContent = mainHeaderRow + '<tr><td valign="top">' + getCESresults(periodType,startDate,endDate,product,team,source) + '</td></tr>' + mainFooterRow; response.write(displayAllContent); } worker function getCESresults function getCESresults(periodType,startDate,endDate,product,team,source) { //Customer Effort Scores var cesFilters = new Array(); cesFilters[0] = new nlobjSearchFilter('custrecord_csateasy2handle', null, 'isnotempty'); if (product && product != 'All') cesFilters.push(new nlobjSearchFilter('custevent_support_product', 'custrecord_csatcasereviewed', 'is', product)); if (!isEmpty(startDate)) cesFilters.push(new nlobjSearchFilter('created', null, 'onOrAfter', startDate)); if (!isEmpty(endDate)) cesFilters.push(new nlobjSearchFilter('created', null, 'onOrBefore', endDate)); if (!isEmpty(team)) cesFilters.push(new nlobjSearchFilter('custevent_supportteam', 'custrecord_csatcasereviewed', 'is', team)); if (source && source != 'All') cesFilters.push(new nlobjSearchFilter('origin', 'custrecord_csatcasereviewed', 'is', source)); var cesColumns = new Array(); cesColumns[0] = new nlobjSearchColumn('internalid', null, 'count'); cesColumns[1] = new nlobjSearchColumn('formulanumeric',null, 'sum').setFormula('DECODE({custrecord_csateasy2handle},4,1,0)'); cesColumns[2] = new nlobjSearchColumn('formulanumeric', null, 'sum').setFormula('DECODE({custrecord_csateasy2handle},5,1,0)'); cesColumns[3] = new nlobjSearchColumn('created', null, 'group').setFunction(periodType); var cesSearchResults = nlapiSearchRecord('customrecord_csat',null,cesFilters,cesColumns); var cesNumofrows = cesSearchResults.length; var cesPeriodName; var cesPeriodTotal = 0; var cesPeriodFoursTotal = 0; var cesPeriodFivesTotal = 0; var cesTotal = 0; var cesFoursTotal = 0; var cesFivesTotal = 0; var cesHeaderRow = '<table class="text" border="1" cellpadding="0" cellspacing="1"><tbody><tr class="portletheadernosort"><td class="portletheadernosort" align="left"><b>Period</b></td><td class="portletheadernosort" align="right"><b># of Scores</b></td><td class="portletheadernosort" align="right"><b>4's</b></td><td class="portletheadernosort" align="right"><b>5's</b></td></tr>'; var cesRowContent = ''; for (i=0; i<cesNumofrows; i++) { cesPeriodName = cesSearchResults[i].getValue(cesColumns[3]); cesPeriodTotal = parseInt(cesSearchResults[i].getValue(cesColumns[0])); cesTotal += cesPeriodTotal; cesPeriodFoursTotal = parseInt(cesSearchResults[i].getValue(cesColumns[1])); cesFoursTotal += cesPeriodFoursTotal; cesPeriodFivesTotal = parseInt(cesSearchResults[i].getValue(cesColumns[2])); cesFivesTotal += cesPeriodFivesTotal; cesRowContent += '<tr><td class="smalltextpad">' +cesPeriodName+ '</td><td class="smalltextpad" align="right">' +cesPeriodTotal+ '</td><td class=smalltextpad" align="right">' +Math.round(cesPeriodFoursTotal / cesPeriodTotal * 100)+ '%</td><td class="smalltextpad" align="right">' +Math.round(cesPeriodFivesTotal / cesPeriodTotal * 100)+ '%</td></tr>'; } var cesFooterRow = '<tr><td class="smalltextpad"><b>All Periods</b></td><td class="smalltextpad" align="right"><b>' +cesTotal+ '</b></td><td class="smalltextpad" align="right"><b>' +Math.round(cesFoursTotal / cesTotal * 100)+ '%</b></td><td class="smalltextpad" align="right"><b>' +Math.round(cesFivesTotal / cesTotal * 100)+ '%</b></td></tr></tbody></table>'; var cesTable = cesHeaderRow + cesRowContent + cesFooterRow; return cesTable; }