This topic contains 3 replies, has 0 voices, and was last updated by chanarbon 8 years ago.
-
AuthorPosts
-
October 25, 2016 at 10:30 am #1635
ssilveri77The example below is from the docs. If I want to exit on the first interation (there could be more than one rec) Would I use return false? The docs do not describe what the return does. function loadAndRunSearch() { var mySearch = search.load({ id: ‘customsearch_my_so_search’ }); mySearch.run().each(function(result) { var entity = result.getValue({ name: ‘entity’ }); var subsidiary = result.getValue( name: ‘subsidiary’ }); return true; });
This is a cached copy. Click here to see the original post. -
October 25, 2016 at 10:46 am #1636
JacksonPIf you’re just trying to check if there is a result you could just run the search at a get range and check the length.
Code:
var salesOrderSearch = search.create({
type: “salesorder”,
filters: [
[“type”,”anyof”,”SalesOrd”],
“AND”,
[“name”,”anyof”, customer],
“AND”,
[“mainline”,”is”,”T”]
],
columns: [
“entity”
]
});var result = salesOrderSearch.run().getRange(0, 1);
if(result.length > 0){ -
October 25, 2016 at 11:34 am #1637
david.smithYes, returning false (or anything besides true) will exit the “each” function.
david.smith replied on 10/25/2016, 05:55 PM: Hmmm, I haven’t tried anything else. Might have to give that a test and find out.
-
October 26, 2016 at 6:00 pm #1638
chanarbonHi ssilveri
For the concern, let’s reference you code
Code:
function loadAndRunSearch() {
var mySearch = search.load({
id: ‘customsearch_my_so_search’
});
mySearch.run().each(function(result) {
var entity = result.getValue({
name: ‘entity’
});
var subsidiary = result.getValue({
name: ‘subsidiary’
});
return true;
});
}
If you want to exit, you can either return anything aside from true or just place a return statement. The .each() iterator requires the boolean operator true to loop through on the callback function to move to another result row. But for this use case, getRange() plays a better approach -
AuthorPosts
You must be logged in to reply to this topic.