How do I use getValue in SuiteScript with a MIN su...
# ask-stanley-ai
j
How do I use getValue in SuiteScript with a MIN summary when I have multiple numeric formula fields in my results?
c
AI generated answer (using internal Slack threads):
To use
getValue
in SuiteScript with a MIN summary when you have multiple numeric formula fields in your results, you can follow these steps: 1. Define column variables for each of your formula fields. This will allow you to reference them later in your
getValue
calls. For example:
Copy code
javascript
var column1 = search.createColumn({
    name: 'formulanumeric',
    formula: 'YOUR_FORMULA_HERE',
    summary: search.Summary.MIN
});
var column2 = search.createColumn({
    name: 'formulanumeric',
    formula: 'YOUR_OTHER_FORMULA_HERE',
    summary: search.Summary.MIN
});
2. Use these column variables in your search columns and in your
Result.getValue
calls. For example:
Copy code
javascript
var mySearch = search.create({
    type: 'transaction',
    columns: [column1, column2]
});
var resultSet = mySearch.run();
resultSet.each(function(result) {
    var minValue1 = result.getValue(column1);
    var minValue2 = result.getValue(column2);
    // Do something with minValue1 and minValue2
    return true;
});
3. If you have null values in your fields and you want to consider them as 0 in your MIN summary, you can use a CASE WHEN statement in your formula. For example:
Copy code
javascript
var column1 = search.createColumn({
    name: 'formulanumeric',
    formula: "CASE WHEN {fieldid} IS NULL THEN 0 ELSE {fieldid} END",
    summary: search.Summary.MIN
});
4. If you want to get the minimum value from multiple fields and ignore null values, you can use the
LEAST
function combined with
NVL
and
COALESCE
. For example:
Copy code
javascript
var column1 = search.createColumn({
    name: 'formulanumeric',
    formula: "LEAST(COALESCE({A},{B},{C}), COALESCE({B},{A},{C}), COALESCE({C},{A},{B}))",
    summary: search.Summary.MIN
});
****** 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.835584819
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827928901
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.827654719
Please provide your feedback on this answer.