I am running a scripted search on a custom record ...
# suitescript
p
I am running a scripted search on a custom record where it is set to find records when there is a match between a zip code in a transaction and a zip code in the customer record. Once found it pulls in a zone and airport code. The problem I am facing is that in the custom records there are instances where a zip code can fall under 2 zones and 2 airports. I need to get only 1. My initial idea was to use the MIN summary on the zone - since the zone's are broken up into letters - with A being the closest zone (and subsequently the closest airport). The problem I am facing is how to have the search find only this 1 value. I tried grouping the airport codes in the search but that gives me all the zones and all the airports - even with the zones set to MIN. How (or is it even possible) to accomplish what I need?
Copy code
var zipcode = recCurrent.getValue({ fieldId: 'custbody217'});
      var zonePUcontactSearch = search.create({
        type: "customrecord715",
        columns: [
            search.createColumn({ name: "custrecord440", summary: "MIN", label: "Zone"}),            
             search.createColumn({name: "custrecord439", summary: "GROUP", label: "Airport Code"})

        ],
        filters : [["custrecord437","is",zipcode ]] 
    });
    var pagedData = zonePUcontactSearch.runPaged({pageSize: 1000});
    
    // iterate the pages
    for( var i=0; i < pagedData.pageRanges.length; i++ ) {

        // fetch the current page data
        var currentPage = pagedData.fetch(i);

        // and forEach() thru all results
        currentPage.data.forEach( function(result) {

            // you have the result row. use it like this....
        var zone= result.getValue({"name":"custrecord440","summary":"MIN"});
        var airportcode = result.getValue({"name":'custrecord439',"summary":"GROUP"});
        console.log("Zone for this zip code is " + zone);
        console.log("Airport Code for this zip code is " + airportcode);
    });
    }
b
kinda hard to tell what you are describing, especially with the useless field ids
but my guess is that you want to sort by zone, and simply only get 1 search result
p
sorry about the useless field id's.
and yes, i only need 1 search result.
b
you dont need to grab multiple pages and process all the search results for each page
you would only need to grab 1 page, and grab the first element of that page