How do I get the value of a second formula numeric...
# suitescript
z
How do I get the value of a second formula numeric?
e
In case you want to keep referencing the columns a little more dynamically, here's an example chapter straight from https://stoic.software/cookbooks/advanced-search/:
Copy code
require(["N/search"], function (s) {

    // Formula for calculating the difference (in Days) between the Date
    // and the Date Created, rounded up with CEIL
    var daysElapsedFormula = "CEIL({date}-{datecreated})";

    var lateEntriesSearch = s.create({
        type: s.Type.TIME_BILL,
        filters: [
            ["formulanumeric: " + daysElapsedFormula, s.Operator.GREATERTHAN, 7]
        ],
        columns: [
            "employee",
            "date",
            "datecreated",
            {
                name: "formulanumeric",
                formula: daysElapsedFormula
            },
            {
                name: "formulanumeric",
                formula: "{date}-{datecreated}"
            }
        ]
    });

    console.log("# Late Entries = " + lateEntriesSearch.runPaged().count);

    var results = lateEntriesSearch.run().getRange({start: 0, end: 1000});
    var lateEntries = results.map(resultToObject);
    console.table(lateEntries);

    function resultToObject(result) {
        var res = result.toJSON();
        console.log(res);
        return {
            employeeName: result.getText({name: "employee"}),
            daysElapsed: res.values.formulanumeric,
            daysElapsedNoRound: res.values.formulanumeric_1
        };
    }
});
Basically, you stringify the search result object with its
toJSON
method, then you can access the columns by name through the
values
property
and as you can see the `formulanumeric`s get that same numbering pattern you're used to
e
Hi @erictgrubaugh! Thanks so much for this! I was struggling some hours today trying to figure out how to get different formula fields. It worked well!
❤️ 1