How to add saved search data to suitelet sublist?
I have created saved search on employee. I have to store each employees net pay, deductions,etc in sublist. In my script I m fetching result as,
[{“sublistpay”:”netpay”,”sublistEmployee”:”Rahul”,”subListAmount”:”17.71″},{“sublistpay”:”tax deduction”,”sublistEmployee”:”Varsha”,”subListAmount”:”110.00″}]
How to set employee wise values on suitelet sublist?
like,
employee netpay tax deduction
Rahul 17.71
Varsha 110.00
The createSublist() function creates a new sublist on the Suitelet form and adds columns for the employee name, net pay, and tax deduction. It then loops through the search results and adds each result to the sublist. The getSearchResults() function loads the saved search and retrieves the search results.
Note that you will need to replace the your_saved_search_id_here placeholder with the ID of your saved search. Also, the field IDs used in the code (custpage_employee, custpage_netpay, and custpage_taxdeduction) are custom field IDs that you can set when creating the sublist fields.
function createSublist(form) {
// Get the search results
var searchResults = getSearchResults();
// Create the sublist
var sublist = form.addSubList({
id: ‘custpage_employees’,
type: serverWidget.SublistType.LIST,
label: ‘Employee Payroll Information’
});
// Add columns to the sublist
sublist.addField({
id: ‘custpage_employee’,
type: serverWidget.FieldType.TEXT,
label: ‘Employee’
});
sublist.addField({
id: ‘custpage_netpay’,
type: serverWidget.FieldType.CURRENCY,
label: ‘Net Pay’
});
sublist.addField({
id: ‘custpage_taxdeduction’,
type: serverWidget.FieldType.CURRENCY,
label: ‘Tax Deduction’
});
// Loop through the search results and add them to the sublist
for (var i = 0; i < searchResults.length; i++) {
var searchResult = searchResults[i];
// Get the employee name and sublist values from the search result
var employeeName = searchResult.getValue(‘sublistEmployee’);
var sublistPay = searchResult.getValue(‘sublistpay’);
var sublistAmount = searchResult.getValue(‘subListAmount’);
// Add the values to the sublist
sublist.setSublistValue({
id: ‘custpage_employee’,
line: i,
value: employeeName
});
if (sublistPay == ‘netpay’) {
sublist.setSublistValue({
id: ‘custpage_netpay’,
line: i,
value: sublistAmount
});
} else if (sublistPay == ‘tax deduction’) {
sublist.setSublistValue({
id: ‘custpage_taxdeduction’,
line: i,
value: sublistAmount
});
}
}
}
function getSearchResults() {
// Define the saved search filters and columns
var filters = [];
var columns = [
search.createColumn({
name: ‘sublistEmployee’
}),
search.createColumn({
name: ‘sublistpay’
}),
search.createColumn({
name: ‘subListAmount’,
summary: search.Summary.SUM
})
];
// Load the saved search and run it
var savedSearch = search.load({
id: ‘your_saved_search_id_here’
});
var searchResults = savedSearch.run().getRange({
start: 0,
end: 1000
});
// Return the search results
return searchResults;
}
Good luck 🙂
Thanks! It helped me lot 🙂
Another Issue I am facing is,
I have created saved search to get employee and sequence number. I have added filter as,
[“sequence”,”anyof”,”100″,”63″,”104″,”65″,”101″,”61″]
And I am getting employees whose sequence is as above filter and also 50, 67,70, 85, 49
Why data is not filtering?
Please help!
filters:
[
[“custrecord_cpa_pay_paycode.custrecord_apd_pcm_sequence”,”anyof”,”100″,”63″,”104″,”65″,”101″,”61″]
],
columns:
[
search.createColumn({
name: “custrecord_apd_pcm_sequence”,
join: “CUSTRECORD_CPA_PAY_PAYCODE”,
summary: “GROUP”,
label: “Sequence”
}),
search.createColumn({
name: “custrecord_cpa_emp_in_annual”,
summary: “GROUP”,
sort: search.Sort.ASC,
label: “Employee”
}),
search.createColumn({
name: “custrecord_cpa_amount”,
summary: “GROUP”,
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;
}