How to calculate the percentage by script of two queries
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 12:17 PM
Hi guys,
I would like to calculate by script the percentage in two different queries that came from the same glide aggregate, so I want to calculate the count of my incident that is category = bussiness and divided by the total incident.
Below following an example.
var incidentGA = new GlideAggregate('incident_sla');
incidentGA.addAggregate('COUNT');
incidentGA.query();
while (incidentGA.next()) {
var percentage = (incidentGA.addEncodedQuery(category=Business) / incidentGA) * 100 // imagine that in my example the count of query is 10 divided by the total that is 100, so in the end I'll divided by 100 to get the percentage calculation.
gs.print(percentage ); // In this example the result should be 10.
}
Please, could someone help me?
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 01:31 PM
Hi Gle,
Please refer to:
Your script fails for me:
Evaluator: com.glide.script.RhinoEcmaError: "Business" is not defined.
script : Line(8) column(0)
5:
6: while (incidentGA.next()) {
7:
==> 8: var percentage = (incidentGA.addEncodedQuery(category=Business) / incidentGA) * 100; // imagine that in my example the count of query is 10 divided by the total that is 100, so in the end I'll divided by 100 to get the percentage calculation.
9:
10:
11:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 02:43 PM
Hi @Bert_c1 1,
Yes my code is not working, thats what I'm looking for, below I'll give another example for what I need, in red is the line that I need help with the code.
var incidentGA = new GlideAggregate('incident');
incidentGA.addAggregate('COUNT');
incidentGA.query();
while (incidentGA.next()) {
var percentage = Here I need to calculate variable "incidentGA" filter the category=business / incidentGA (with no filter) * 100
gs.print(percentage );
}
Many Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2023 06:05 PM
hi Gle,
Did you review the API that I posted? Your use of GlideAggregate() is wrong. What field on the incident or incident_sla table do you want get an 'aggregate' on? Please review the documentation at the link I posted.