This topic contains 3 replies, has 0 voices, and was last updated by chanarbon 8 years ago.

  • Author
    Posts
  • #1635

    ssilveri77

    The 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.

  • #1636

    JacksonP

    If 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){

  • #1637

    david.smith

    Yes, 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.

  • #1638

    chanarbon

    Hi 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

You must be logged in to reply to this topic.