Fetch the workflow field values related to the record deployed in suite-script using a saved search

Recently I had to fetch the values of workflow fields from within a Suitelet that is triggered by a button action. Workflow fields can be updated based on field value updates in a NetSuite record but there is no direct way of fetching these values in a script. For this, I used a saved search and fetched the workflow history field values. We can see the changes in the Workflow fields in the ‘Workflow history’ section in the ‘System Information’ subtab. These values can be fetched inside most suite scripts using a saved search with a ‘join’ action. Refer to the following script for more; here I am fetching values from a ‘Vendor bill’ record.

let vendorbillSearchObj = search.create({
        type: "vendorbill",
        filters:
            [
                    ["type","anyof","VendBill"],
                    "AND",
                    ["internalid","anyof",vendorBillRecordId]
            ],
        columns:
            [
                    search.createColumn({
                            name: "dateexitedstate",
                            join: "workflowHistory",
                            summary: "MAX",
                            sort: search.Sort.ASC,
                            label: "Date Exited State"
                    }),
                    search.createColumn({
                            name: "options",
                            join: "workflowHistory",
                            summary: "MAX",
                            label: "Options"
                    })
            ]
});
let searchResultCount = vendorbillSearchObj.runPaged().count;
log.debug("vendorbillSearchObj result count", searchResultCount);
let searchResultObj = [];
vendorbillSearchObj.run().each(function(result){
        // .run().each has a limit of 4,000 results
        searchResultObj.push(result);
        return true;
});

Leave a comment

Your email address will not be published. Required fields are marked *