this function var mySearch = search.create({ ...
# ask-stanley-ai
n
this function var mySearch = search.create({ type: search.Type.TRANSACTION, filters: [ ["type", "anyof", ["CashRfnd", "CashSale", "CustCred", "CustInvc"]], "AND", ["mainline", "is", "F"], "AND", // ["type", "anyof", "InvtPart"], // "AND", ["item", "anyof", itemId+""], "AND", ["taxline", "is", "F"], "AND", ["shipping", "is", "F"], "AND", ["cogs", "is", "F"], "AND", ["status", "noneof", ["CashSale:A", "CustRfnd:R", "CustRfnd:V", "CustInvc:D", "CustInvc:E", "CustInvc:V"]] ], columns: [ search.createColumn({ name: "internalid", join: "item", summary: "GROUP", label: "Internal ID" }), search.createColumn({ name: "item", summary: "GROUP", label: "Item" }), search.createColumn({ name: "custitem_atc_item_brand", join: "item", summary: "GROUP", label: "ATC Item Brand" }), search.createColumn({ name: "displayname", join: "item", summary: "GROUP", label: "Display Name" }), search.createColumn({ name: "formulacurrency", summary: "SUM", label: "Formula (Currency)", formula: "CASE WHEN {type} IN ('Invoice', 'Cash Sale') AND {trandate} BETWEEN TO_DATE('01/01/2024', 'MM/DD/YYYY') AND TO_DATE('12/31/2024', 'MM/DD/YYYY') THEN {quantity} ELSE NULL END" }), search.createColumn({ name: "formulacurrency", summary: "SUM", label: "Formula (Currency)", formula: "SUM( CASE WHEN {type} IN ('Invoice', 'Cash Sale') AND {trandate} BETWEEN ADD_MONTHS(SYSDATE, -12) AND SYSDATE THEN {quantity} ELSE 0 END )" }), search.createColumn({ name: "formulacurrency", summary: "SUM", label: "Formula (Currency)", formula: "CASE WHEN {type} IN ('Invoice', 'Cash Sale') AND {trandate} BETWEEN ADD_MONTHS(SYSDATE, -12) AND SYSDATE THEN {quantity} WHEN {type} IN ('Credit Memo', 'Cash Refund') AND {trandate} BETWEEN ADD_MONTHS(SYSDATE, -12) AND SYSDATE THEN +{quantity} ELSE NULL END" }), search.createColumn({ name: "formulacurrency", summary: "SUM", label: "Formula (Currency)", formula: "(CASE WHEN {type} IN ('Invoice', 'Cash Sale') THEN {quantity} WHEN {type} IN ('Credit Memo', 'Cash Refund') THEN +{quantity} ELSE NULL END) / 12" }), search.createColumn({ name: "formulacurrency", summary: "SUM", label: "Formula (Currency)", formula: "((CASE WHEN {type} IN ('Invoice', 'Cash Sale') THEN {quantity} WHEN {type} IN ('Credit Memo', 'Cash Refund') THEN +{quantity} ELSE NULL END) / 12) * 4" }) ] }); // Execute the search and return results var searchResults = []; mySearch.run().each(function(result) { searchResults.push(result); return true; // Continue iteration }); returns [{"values":{"GROUP(item.internalid)":[{"value":"316","text":"316"}],"GROUP(item)":[{"value":"316","text":"10-16.5 GX XD2010 10 PR 134 A2 TL"}],"GROUP(item.custitem_atc_item_brand)":[{"value":"10","text":"GALAXY"}],"GROUP(item.displayname)":"GX170601","SUM(formulacurrency)":"533.00","SUM(formulacurrency)_1":"561.00","SUM(formulacurrency)_2":"554.00","SUM(formulacurrency)_3":"46.167","SUM(formulacurrency)_4":"184.667"}}] i want to return each of the results
c
AI generated answer (using internal Slack threads):
The function you provided is a SuiteScript search that is designed to return a set of transactions based on the specified filters and columns. The filters are set to return transactions of type CashRfnd, CashSale, CustCred, CustInvc that are not mainline, taxline, shipping, cogs and have a specific status. The columns are set to return the internal ID, item, ATC Item Brand, Display Name, and several calculated values based on the transaction type and date. The result you provided is a single result from this search, represented as a JSON object. If you want to return each of the results from the search, you would need to iterate over the
searchResults
array and process each result individually. Here's a simple example of how you might do that:
Copy code
javascript
searchResults.forEach(function(result) {
    var values = result.values;
    var internalId = values['GROUP(item.internalid)'][0].value;
    var item = values['GROUP(item)'][0].value;
    var atcItemBrand = values['GROUP(item.custitem_atc_item_brand)'][0].value;
    var displayName = values['GROUP(item.displayname)'];
    var formulaCurrency = values['SUM(formulacurrency)'];
    var formulaCurrency1 = values['SUM(formulacurrency)_1'];
    var formulaCurrency2 = values['SUM(formulacurrency)_2'];
    var formulaCurrency3 = values['SUM(formulacurrency)_3'];
    var formulaCurrency4 = values['SUM(formulacurrency)_4'];

    // Now you can do something with these values...
});
This code will loop over each result in the
searchResults
array, extract the values from each result, and then do something with those values. You would replace the comment with whatever you want to do with the values. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.87130028
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.869320631
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.867789626
Please provide your feedback on this answer.