RE: How to get Sequencewise amount from saved search?

I have created saved search to get total amount of net pay, total amount of tax deduction, etc. I used group and sum in saved search. Now I am getting result as:

getSequence 104
getAmounts 5213.89
getSequence 100
getAmounts 2564.21

sequence means–100 for net pay, 104 for tax

How to get result as, sequence 100 amount 2564.21, sequence 104 amount 5213.89, in suitescript? Please help someone!

 

Below is my code:

 

function getEmployeeAmountTotals() {
            //var searchResultCount;
            var customrecord_cpa_annual_salary_calculatiSearchObj = search.create({
                type: “customrecord_cpa_annual_salary_calculati”,
                filters:
                [
                   [“custrecord_cpa_pay_paycode”,”anyof”,”28″,”29″,”330″,”30″,”101″,”34″]
                ],
                columns:
                [
                   search.createColumn({
                      name: “custrecord_apd_pcm_sequence”,
                      join: “CUSTRECORD_CPA_PAY_PAYCODE”,
                      summary: “GROUP”,
                      label: “Sequence”
                   }),
                   search.createColumn({
                      name: “custrecord_cpa_amount”,
                      summary: “SUM”,
                      sort: search.Sort.ASC,
                      label: “Amount”
                   })
                ]
             });
             searchResultCount = customrecord_cpa_annual_salary_calculatiSearchObj.runPaged().count;
             log.debug(“Total Employees”,searchResultCount);
            resultObj = [];
            var saveSearchResult = customrecord_cpa_annual_salary_calculatiSearchObj.run()
            saveSearchResult.each(function (item) {
                obj = {}
                obj.sequence= item.getValue({name: “custrecord_apd_pcm_sequence”,
                join: “CUSTRECORD_CPA_PAY_PAYCODE”,
                summary: “GROUP”,
                label: “Sequence”});
                obj.amounts= item.getValue({name: “custrecord_cpa_amount”,
                summary: “SUM”,
                sort: search.Sort.ASC,
                label: “Amount”});
                resultObj.push(obj)
                return true
            })
           // log.debug(“amount”,obj.amount);
            return resultObj;
       }
        var employeeAmountTotals = getEmployeeAmountTotals();
        for(vari=0;i<employeeAmountTotals.length;i++)
        {
            var getSequence=employeeAmountTotals[i].sequence;
            var getAmounts=employeeAmountTotals[i].amounts;
            log.debug(“getSequence”,getSequence);
            log.debug(“getAmounts”,getAmounts);
        }
Maira S Beginner Asked on March 1, 2023 in SuiteScript.
Add Comment
1 Answers

seems like you want to sort the results by low sequence first…

if you want to sort the results by SEQUENCE, then you should sort by SEQUENCE instead of sorting by AMOUNT (sort: search.Sort.ASC)

in my simulation, you should have retrieved AMOUNT2564.21 and SEQUENCE100 as the first data because you sorted the result by ASCENDING AMOUNT (this should translate to dealing with lowest amounts first)

… … …

here is a way to sort an ARRAY of OBJECTS by OBJECT property/attribute:

var employeeAmountTotals = [{amounts:5213.89, sequence:104}, {amounts:2564.21, sequence:100}]

//sort by sequence
employeeAmountTotals = employeeAmountTotals.sort(function(a, b){
return Number(a.sequence) – Number(b.sequence)
})

console.log(“employeeAmountTotals after sorting”, employeeAmountTotals);

for(var i=0;i<employeeAmountTotals.length;i++)
{
var getSequence=employeeAmountTotals[i].sequence;
var getAmounts=employeeAmountTotals[i].amounts;
console.log(“getSequence”,getSequence);
console.log(“getAmounts”,getAmounts);
}

Rookie Answered on March 7, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.