GlideRecord With condition (year=2023 AND month>=3) OR (year=2024 AND month<=2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 05:04 AM
Hi,
I want to get all records from a table using GlideRecord but my condition is from two AND conditions connected using an OR.
Actually, this would be fine, but it won't work as encodedQueries seem not to support grouping with ()
var totalRealRevenue = 0;
// GlideRecord auf die Tabelle 'sn_customerservice_consumption_metrics' ausführen
var gr = new GlideRecord('sn_customerservice_consumption_metrics');
gr.addEncodedQuery('(u_year=2023^u_month>=3)^(u_year=2024^u_month<=2)'); // Die Bedingungen korrekt gruppiert
gr.query();
while (gr.next()) {
// Ausgabe der relevanten Felder für jeden Datensatz
gs.info('Revenue: Month = ' + gr.u_month + ', Year = ' + gr.u_year + ', Revenue = ' + gr.u_real_revenue);
// Summiere den Umsatz (u_real_revenue), falls der Wert vorhanden ist
totalRealRevenue += parseFloat(gr.u_real_revenue || 0) || 0;
}
// Gesamtsumme ausgeben
gs.info('Total Real Revenue: ' + totalRealRevenue);
How can I do something like (year=2023 AND month>=3) OR (year=2024 AND month<=2)
Regards
Sirko
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2024 05:29 AM - edited 12-04-2024 05:31 AM
Build the query in a list view filter using the correct combination of ANDs and ORs that meet this criteria. You can then right-click on the last breadcrumb and copy query to see the correct encoded query. In an out of box example (active=true and state=New) or (active=false and state=Closed) the manual filter looks like this:
and the resulting encoded query is:
active=true^state=1^NQactive=false^state=7
So it looks like your example would be:
gr.addEncodedQuery('u_year=2023^u_month>=3^NQu_year=2024^u_month<=2'); // Die Bedingungen korrekt gruppiert