How to add saved search result to suitelet sublist

There is a store calculation record. On that, there are employee, sequence number, and amount. If sequence = 100, then its net pay, sequence is 63, then its CPP employee, sequence is 104, then its CPP employer, sequence is 65, then its EIEmployee, sequence is 101, then its EI Employer, sequence is 61 then its tax deduction. Create a sublist in suitelet script 2.0 and add employee, net pay, cpp employee, cpp employer, ei employee, ei employer, tax deduction, and total to the sublist.

 

I have created sublsit but not able to add proper values. Please hep me!

 

/**
* @NApiVersion 2.x
*@NScriptType Suitelet
* … more options …
*/
define([‘N/ui/serverWidget’,’N/record’,’N/search’], function(serverWidget,record,search) {
    function onRequest(context) {
        var request = context.request;
        var response = context.response;
      if (context.request.method === ‘GET’) {
        try{
            var form = serverWidget.createForm({ title: ‘Funds Form’ });
            //Total Employees Sublist Saved Search
      var sublistEmpName;
            var sublistNetPay;
            var sublistCPPEmployee;
      var sublistCPPEmployeer;
      var sublistEIEmployee;
      var sublistEIEmployeer;
      var sublistTaxDeduction;
            function getEmployeeSublistDetails() {
              var customrecord_cpa_annual_salary_calculatiSearchObj = search.create({
                  type: “customrecord_cpa_annual_salary_calculati”,
                  filters:
                  [
                    [“custrecord_cpa_pay_paycode.custrecord_apd_pcm_sequence”,”anyof”,”100″,”63″,”104″,”65″,”101″,”61″],
                    “AND”,
                     [“custrecord_cpa_sub”,”anyof”,”2″],
                     “AND”,
                     [“custrecord_cpa_lg”,”anyof”,”9″],
                     “AND”,
                     [“custrecord_cpa_period_no”,”anyof”,”1″],
                     “AND”,
                     [“custrecord_cpa_paycheck_occ”,”anyof”,”3″],
                     “AND”,
                     [“custrecord_store_cal_batch”,”anyof”,”1″],
                     “AND”,
                     [“custrecord_cpa_pp_year”,”anyof”,”3″],
                     “AND”,
                     [“custrecord_cpa_emp_in_annual.custentity_cpa_pay_mode”,”anyof”,”1″]
                  ],
                  columns:
                  [
                     search.createColumn({
                        name: “internalid”,
                        join: “CUSTRECORD_CPA_EMP_IN_ANNUAL”,
                        label: “Internal ID”
                     }),
                     search.createColumn({name: “custrecord_cpa_emp_in_annual”, label: “Employee”}),
                     search.createColumn({
                        name: “custrecord_apd_pcm_sequence”,
                        join: “CUSTRECORD_CPA_PAY_PAYCODE”,
                        sort: search.Sort.ASC,
                        label: “Sequence”
                     }),
                     search.createColumn({name: “custrecord_cpa_amount”, label: “Amount”})
                  ]
               });
                 searchResultCount = customrecord_cpa_annual_salary_calculatiSearchObj.runPaged().count;
                 log.debug(“Total Sublist Employees”,searchResultCount);
                resultObjSublist = [];
                var saveSearchResult = customrecord_cpa_annual_salary_calculatiSearchObj.run();
                saveSearchResult.each(function (item) {
                    objSublist = {}
                    objSublist.sublisteid=item.getValue({  name: “internalid”,
                    join: “CUSTRECORD_CPA_EMP_IN_ANNUAL”,
                    label: “Internal ID”});
                    objSublist.sublistename=item.getText({name: “custrecord_cpa_emp_in_annual”, label: “Employee”});
                    objSublist.sublistesequence=item.getValue({ name: “custrecord_apd_pcm_sequence”,
                    join: “CUSTRECORD_CPA_PAY_PAYCODE”,
                    sort: search.Sort.ASC,
                    label: “Sequence”});
                    objSublist.sublisteamount=item.getValue({name: “custrecord_cpa_amount”, label: “Amount”});
                    resultObjSublist.push(objSublist)
                    return true
                })
                return resultObjSublist;
           }
           //Sublist Code Bigin…….
        var empSublist=form.addSublist({
                id: ‘custpage_payroll’,
                type: serverWidget.SublistType.LIST,
                label: ‘EMPLOYEE PAYROLL INFORMATION’
                });
                empSublist.addField({
                    id: ‘custpage_sublistemployee’,
                    type: serverWidget.FieldType.TEXT,
                    label: ‘Employee’
                    });
          empSublist.addField({
                    id: ‘custpage_sublistnetpay’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘Net Pay’
                    });
          empSublist.addField({
                    id: ‘custpage_sublistcppemployee’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘CPP Employee’
                    });
          empSublist.addField({
                    id: ‘custpage_sublistcppemployer’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘CPP Employer’
                    });
          empSublist.addField({
                    id: ‘custpage_sublisteiemployee’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘EI Employee’
                    });
          empSublist.addField({
                    id: ‘custpage_sublisteiemployer’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘EI Employer’
                    });
          empSublist.addField({
                    id: ‘custpage_sublisttaxdeduction’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘Income Tax Deduction’
                    });
          empSublist.addField({
                    id: ‘custpage_sublisttotal’,
                    type: serverWidget.FieldType.CURRENCY,
                    label: ‘Total’
                    });
                    var employeeSublistDetails = getEmployeeSublistDetails();
                    log.debug(“employeeSublistDetails”,employeeSublistDetails);
                    var ename=employeeSublistDetails[i].sublistEmpName;
                    var eamount=employeeSublistDetails[i].sublisteamount;
           /* empSublist.setSublistValue({
            id: ‘custpage_sublistemployee’,
            line: j,
            value: sublistEmpName
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublistnetpay’,
            line: j,
            value: sublistNetPay
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublistcppemployee’,
            line: j,
            value: sublistCPPEmployee
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublistcppemployer’,
            line: j,
            value: sublistCPPEmployer
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublisteiemployee’,
            line: j,
            value: sublistEIEmployee
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublisteiemployer’,
            line: j,
            value: sublistEIEmployeer
            });
            empSublist.setSublistValue({
            id: ‘custpage_sublisttaxdeduction’,
            line: j,
            value: sublistTaxDeduction
            });*/
          context.response.writePage(form);
        } catch (error) {
            log.debug(‘Error’, error);
        }
        } else if (context.request.method === ‘POST’) {
           log.debug(“Suitelet is posting.”)
        }
    }
    return{
      onRequest:onRequest
    }
    })
Beginner Asked on March 5, 2023 in SuiteScript.
Add Comment
1 Answer(s)

You need to properly iterate through the list of data you have just retrieved and stored in variable resultObjSublist

where variable j  is your counter, it starts with 0, it can also represent the row/index of your sublist

for(var j = 0 ; j < resultObjSublist.length ; j++){

    empSublist.setSublistValue({
        id: ‘custpage_sublistemployee’,
        line: j,
        value: sublistEmpName
    });

//continue coding

}

 

/**
* @NApiVersion 2.x
*@NScriptType Suitelet
* … more options …
*/
define([‘N/ui/serverWidget’,’N/record’,’N/search’], function(serverWidget,record,search) {
function onRequest(context) {
var request = context.request;
var response = context.response;
if (context.request.method === ‘GET’) {
try{
var form = serverWidget.createForm({ title: ‘Funds Form’ });
//Total Employees Sublist Saved Search
var sublistEmpName;
var sublistNetPay;
var sublistCPPEmployee;
var sublistCPPEmployeer;
var sublistEIEmployee;
var sublistEIEmployeer;
var sublistTaxDeduction;
function getEmployeeSublistDetails() {
var customrecord_cpa_annual_salary_calculatiSearchObj = search.create({
type: “customrecord_cpa_annual_salary_calculati”,
filters:
[
[“custrecord_cpa_pay_paycode.custrecord_apd_pcm_sequence”,”anyof”,”100″,”63″,”104″,”65″,”101″,”61″],
“AND”,
[“custrecord_cpa_sub”,”anyof”,”2″],
“AND”,
[“custrecord_cpa_lg”,”anyof”,”9″],
“AND”,
[“custrecord_cpa_period_no”,”anyof”,”1″],
“AND”,
[“custrecord_cpa_paycheck_occ”,”anyof”,”3″],
“AND”,
[“custrecord_store_cal_batch”,”anyof”,”1″],
“AND”,
[“custrecord_cpa_pp_year”,”anyof”,”3″],
“AND”,
[“custrecord_cpa_emp_in_annual.custentity_cpa_pay_mode”,”anyof”,”1″]
],
columns:
[
search.createColumn({
name: “internalid”,
join: “CUSTRECORD_CPA_EMP_IN_ANNUAL”,
label: “Internal ID”
}),
search.createColumn({name: “custrecord_cpa_emp_in_annual”, label: “Employee”}),
search.createColumn({
name: “custrecord_apd_pcm_sequence”,
join: “CUSTRECORD_CPA_PAY_PAYCODE”,
sort: search.Sort.ASC,
label: “Sequence”
}),
search.createColumn({name: “custrecord_cpa_amount”, label: “Amount”})
]
});
searchResultCount = customrecord_cpa_annual_salary_calculatiSearchObj.runPaged().count;
log.debug(“Total Sublist Employees”,searchResultCount);
resultObjSublist = [];
var saveSearchResult = customrecord_cpa_annual_salary_calculatiSearchObj.run();
saveSearchResult.each(function (item) {
objSublist = {}
objSublist.sublisteid=item.getValue({ name: “internalid”,
join: “CUSTRECORD_CPA_EMP_IN_ANNUAL”,
label: “Internal ID”});
objSublist.sublistename=item.getText({name: “custrecord_cpa_emp_in_annual”, label: “Employee”});
objSublist.sublistesequence=item.getValue({ name: “custrecord_apd_pcm_sequence”,
join: “CUSTRECORD_CPA_PAY_PAYCODE”,
sort: search.Sort.ASC,
label: “Sequence”});
objSublist.sublisteamount=item.getValue({name: “custrecord_cpa_amount”, label: “Amount”});
resultObjSublist.push(objSublist)
return true
})
return resultObjSublist;
}
//Sublist Code Bigin…….
var empSublist=form.addSublist({
id: ‘custpage_payroll’,
type: serverWidget.SublistType.LIST,
label: ‘EMPLOYEE PAYROLL INFORMATION’
});
empSublist.addField({
id: ‘custpage_sublistemployee’,
type: serverWidget.FieldType.TEXT,
label: ‘Employee’
});
empSublist.addField({
id: ‘custpage_sublistnetpay’,
type: serverWidget.FieldType.CURRENCY,
label: ‘Net Pay’
});
empSublist.addField({
id: ‘custpage_sublistcppemployee’,
type: serverWidget.FieldType.CURRENCY,
label: ‘CPP Employee’
});
empSublist.addField({
id: ‘custpage_sublistcppemployer’,
type: serverWidget.FieldType.CURRENCY,
label: ‘CPP Employer’
});
empSublist.addField({
id: ‘custpage_sublisteiemployee’,
type: serverWidget.FieldType.CURRENCY,
label: ‘EI Employee’
});
empSublist.addField({
id: ‘custpage_sublisteiemployer’,
type: serverWidget.FieldType.CURRENCY,
label: ‘EI Employer’
});
empSublist.addField({
id: ‘custpage_sublisttaxdeduction’,
type: serverWidget.FieldType.CURRENCY,
label: ‘Income Tax Deduction’
});
empSublist.addField({
id: ‘custpage_sublisttotal’,
type: serverWidget.FieldType.CURRENCY,
label: ‘Total’
});
var employeeSublistDetails = getEmployeeSublistDetails();
log.debug(“employeeSublistDetails”,employeeSublistDetails);
var ename=employeeSublistDetails[i].sublistEmpName;
var eamount=employeeSublistDetails[i].sublisteamount;

 

//START – MODIFIED THIS BLOCK

for(var j = 0 ; j < resultObjSublist.length ; j++){

empSublist.setSublistValue({
id: ‘custpage_sublistemployee’,
line: j,
value: sublistEmpName
});
empSublist.setSublistValue({
id: ‘custpage_sublistnetpay’,
line: j,
value: sublistNetPay
});
empSublist.setSublistValue({
id: ‘custpage_sublistcppemployee’,
line: j,
value: sublistCPPEmployee
});
empSublist.setSublistValue({
id: ‘custpage_sublistcppemployer’,
line: j,
value: sublistCPPEmployer
});
empSublist.setSublistValue({
id: ‘custpage_sublisteiemployee’,
line: j,
value: sublistEIEmployee
});
empSublist.setSublistValue({
id: ‘custpage_sublisteiemployer’,
line: j,
value: sublistEIEmployeer
});
empSublist.setSublistValue({
id: ‘custpage_sublisttaxdeduction’,
line: j,
value: sublistTaxDeduction
});

}
context.response.writePage(form);
} catch (error) {
log.debug(‘Error’, error);
}
} else if (context.request.method === ‘POST’) {
log.debug(“Suitelet is posting.”)
}
}
return{
onRequest:onRequest
}
})

Rookie Answered on March 6, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor