I've created a saved search in a script, I then capture the internalID of the new saved search and append it to a string to create a URL to the saved search results.
This URL string sets a dynamic URL field on a customer record with an 'on load' user event script. So basically, when the customer record loads there is a link under the address to find nearby prospects & customers (with the same FSA or 1st three digits of their postal code).
It's still in draft mode (I'm going to restrict to Canadian addresses, etc. later), but at this point I was wondering if it is possible to add footer filters to saved searches created in a user event Suitescript? (At this point our Netsuite version is 2012.1). I'm just a suitescript dabbler (not a real coder), so I appreciate any help.
Also, if any of you know another way to create and display saved search results without having to save them that would be great as well. I only want at most 1 saved search per user, but if a user has many company tabs open and clicks the link it will always linked to the last loaded search (without a refresh).
Thanks,
Rob.
Here is the code below just for reference:
function beforeLoadFunc(type, form) { // We only want this script to run when being triggered in the user interface var currentContext = nlapiGetContext(); var executionContext = currentContext.getExecutionContext(); if (executionContext == 'userinterface') { // We want a unique ID for each user to only have one saved search per user var userID = nlapiGetUser(); var userName = nlapiLookupField('employee', userID, 'entityid'); // Get the company billing address postal code var companyZip = nlapiGetFieldValue('billzip'); // Parse the FSA from the postal code var companyFSA = companyZip.substring(0,3); // Only run if a valid FSA is returned, otherwise exit if (companyFSA != null && companyFSA.length == 3) { // Define search filters var filters = new Array(); filters[0] = new nlobjSearchFilter( 'formulatext', null, 'startswith', companyFSA ); filters[0].setFormula('{billzipcode}'); filters[1] = new nlobjSearchFilter( 'isjob', null, 'is', 'F' ); filters[2] = new nlobjSearchFilter( 'stage', null, 'noneof', 'LEAD' ); // Define search columns var columns = new Array(); columns[0] = new nlobjSearchColumn( 'internalid' ); columns[1] = new nlobjSearchColumn( 'companyname' ); columns[2] = new nlobjSearchColumn( 'phone' ); columns[3] = new nlobjSearchColumn( 'billcity' ); columns[4] = new nlobjSearchColumn( 'billaddress1' ); columns[5] = new nlobjSearchColumn( 'billzipcode' ); columns[6] = new nlobjSearchColumn( 'entitystatus' ); columns[7] = new nlobjSearchColumn( 'url' ); columns[8] = new nlobjSearchColumn( 'custentity14' ); // SWX support level columns[9] = new nlobjSearchColumn( 'salesrep' ); var searchTitle = 'Nearby Companies for ' + userName; var scriptID = 'customsearch_nearby' + userID; try { var search = nlapiLoadSearch('customer', scriptID); search.deleteSearch(); var search = nlapiCreateSearch( 'customer', filters, columns ); } catch(err) { var search = nlapiCreateSearch( 'customer', filters, columns ); } var searchId = search.saveSearch(searchTitle, scriptID); var savedSearchURL ='https://system.netsuite.com/app/common/search/searchresults.nl?searchid=' + searchId; nlapiSetFieldValue('custentity_nearbycompanies', savedSearchURL, null, true); } else { // Exit since this company does not have a billing address set } } }