```var nextApprover; var employeeSearchObj = searc...
# suitescript
k
Copy code
var nextApprover;
var employeeSearchObj = search.create({
    type: "employee",
    filters:
        [
        ],
    columns:
        [
            search.createColumn({
                name: "entityid",
                sort: search.Sort.ASC,
                label: "Name"
            }),

        ]
});

var searchResultCount = employeeSearchObj.runPaged().count;

console.log("employeeSearchObj result count",searchResultCount);
employeeSearchObj.run().each(function(result){
    // .run().each has a limit of 4,000 results


                console.log(result.id);
                console.log(employeeId);
               

               if(result.id === employeeId){

                    console.log("Match")


                }
    return true;
});

console.log("Next Approved id value: " +  nextApprover)
c
Quick note about sharing code in this Slack workspace -- please use snippets to keep the channel messages from being too bulky. As for this one in particular, I believe you should be using
return true;
in your iterator so it continues looping through more than just the first result.
Also, you're doing
result.id
when you should be doing
result.getValue("entityid")
. Next, what is
employeeId
? Is it the internal ID of the employee record, or the same field value of
entityid
?
b
i dont even think that matters, the return value of the each callback is being used incorrectly
💯 1
e
As for this one in particular, I believe you should be using return true; in your iterator so it continues looping through more than just the first result.
If I could go back in time to the start of my SuiteScript career, I would keep a counter of how many times this question/problem occurs.
😆 1
b
after you fixed the return value, you can answer clay's question about the employeeId, but i personally think its irrelevant
you should make it a filter in the search so you dont actually need to check each search result, its the entire point of the filters
🙌 2
as written, there isnt much point to comparing result.id to anything but the internal id, and if you had the internal id, you really wouldnt need to search through multiple search results
if the employeedId is instead the entity id, you would put a filter for it, so you wouldnt need to filter the results yourself
c
Thanks for taking the time to consider the whole script and not just tiny pieces like my coffee-starved brain was doing @battk