how do you fetch formula columns of a search in su...
# suitescript
r
how do you fetch formula columns of a search in suitesccript, when multiple exist like I have 2 formulanumeric column, with label c1 and c2, how to fetch those values in suitescript the below code is giving same output for both of them
Copy code
const c3 = result.getValue({ name: 'formulanumeric', label: 'c1' })
const c4 = result.getValue({ name: 'formulanumeric', label: 'c2' })
b
use Result.getValue(column) with a Column that matches the column used to create the serach column, including the formula parameter
a
Columns.js
This is how you can handle multiple formulas of the same type, plus an added advantage using this pattern is that you have a single place where you create or updates columns.
r
below is the code for the search:
Copy code
var salesorderSearchObj = search.create({
            type: 'salesorder',
            filters: [
                ['type', 'anyof', 'SalesOrd'],
                'AND',
                ['mainline', 'is', 'T'],
                'AND',
                ['internalidnumber', 'equalto', '15580268']
            ],
            columns: [
                search.createColumn({ name: 'internalid', label: 'Internal ID' }),
                search.createColumn({ name: 'amount', label: 'Amount' }),
                search.createColumn({
                    name: 'formulatext',
                    formula: '{amount}+100',
                    label: 'c1'
                }),
                search.createColumn({
                    name: 'formulatext',
                    formula: '{amount}+200',
                    label: 'c2'
                }),
                search.createColumn({
                    name: 'formulanumeric',
                    formula: '{amount}+300',
                    label: 'c3'
                }),
                search.createColumn({
                    name: 'formulanumeric',
                    formula: '{amount}+400',
                    label: 'c4'
                })
            ]
        })
I could get the details by getting all columns using var myColumns = salesorderSearchObj.columns and then itterating overall the columns, but was trying to avoid that. I have done this in past, but can't seem to remember how.
e
Here's how I do it in my SuiteScript Cookbook in a way that doesn't force you to hold on to or dig up a reference to the right
Column
instance. The
resultToObject
function is the important bit.
👀 1
r
ah, it was _1 and _2 ty, this is what i was looking for.
✅ 1
e
It'd be nice if the key could be a little more programmatic, like
formulanumeric_${label}
, but I still prefer this to trying to keep the
Column
instance around. I'm nearly always processing my results in a different function/scope than where I created the
Search
b