Passing Parameter to GlideAggregate is NOT working in Server Scripts but code works in Background Sc
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 06:23 AM
Hi ,
I have created a custom Widget and in there I query the core_company Table and get the company name and pass it in to GlideAggregate query to get the Aggregated results.
When I pass "sys_Id" of the company record (from core_company) to GlideAggregate as below to filter results, it doesn't give any results. However, same below code gives me results when it runs in Scripts Backgrounds.
gr.addEncodedQuery('invoice_customer=' + companySysID);
No results If I even pass the company name as Query Parameter.
Any Clue Friends ?
Here is the my code.
//------------------------------------------------------------------------------------------------------------------
var grRecCompany = new GlideRecord('core_company');
grRecCompany.addNotNullQuery('invoice_customer.name');
grRecCompany .setLimit(10);
grRecCompany.query();
var companySysID = null;
var companyCountry = null;
var comapnyName = null;
var resultArray = [];
var count = 0;
while (grRecCompany.next()) {
var record = {};
companySysID = grRecCompany.sys_id.getValue();
companyName = grRecCompany.name.getValue();
companyCountry = grRecCompany.country.getValue();
var gr = new GlideAggregate("invoice_invoice_item");
gr.addEncodedQuery('invoice_customerISNOTEMPTY');
//gr.addEncodedQuery('invoice_customer.name=' + companyName);
gr.addEncodedQuery('invoice_customer=' + companySysID); //If we comment this line then I get the results.
gr.addAggregate('SUM', 'invitem_total_travel_time');
gr.addAggregate('SUM', 'invitem_total_work_time');
gr.addAggregate('SUM', 'invitem_total_price');
gr.groupBy('invoice_customer');
gr.groupBy('invitem_product');
gr.setLimit(100);
gr.query();
// Loop through the records and add them to the array
while (gr.next()) {
var recordInvoice = {};
recordInvoice.service = gr.invitem_product.name.getValue();
recordInvoice.total_price = gr.getAggregate('SUM', 'invitem_total_price');
recordInvoice.currency = gr.invitem_contract.u_currency.getValue();
count = count + 1;
resultArray.push(recordInvoice);
}
}
0 REPLIES 0