- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 10:47 PM
Hi ,
I am doing gliderecord on one table in background script
so basically, its 1 table that has questions and if we group them category, each category has 2 questions and each question will have some value stored in integer field.
what i want to do is, for each category i want a value (this value will be multiplication of values of questions within that category) and i want to sum all values of all categories
Hope you got it
Currently im getting 2 values of 2 questions of category, instead of that i want to print multiplication of them
please have a look at code and tell me what i need to add
var asmt= new GlideRecord('asmt_assessment_instance_question');
asmt.addEncodedQuery('instance=41c5ebfe1bbb5110c1cb4197dc4bcb6f^category=d7d0b13f1b359910c1cb4197dc4bcbbb');
asmt.query();
while(asmt.next()){
gs.print(asmt.value);
}
Im getting result of this as
2
1
which are the values of 2 questions within that category
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 12:46 AM
var a = 1;
var asmt= new GlideRecord('asmt_assessment_instance_question');
asmt.addEncodedQuery('instance=41c5ebfe1bbb5110c1cb4197dc4bcb6f^category=d7d0b13f1b359910c1cb4197dc4bcbbb'); // add or remove the category filter accordingly for all or 1.
asmt.query();
while(asmt.next())
{
a = pareInt(asmt.value)+parseInt(a); // this will sum up.
}
gs.print(a);
Please mark the answer correct/helpful accordingly.
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 12:55 AM
Thanks a lot , its working for me!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 09:25 PM
hey, i tried below code to get total sum of values of all categories , but not getting why its not working, can you have a look please?
var rec1 = new GlideRecord(‘asmt_assessment_instance_question’);
rec1.addEncodedQuery(‘instance=41c5ebfe1bbb5110c1cb4197dc4bcb6f’);
rec1.query();
while(rec1.next()){
var arr_cat = [];
if (arr_cat.indexOf(‘’+rec1.category)===-1){
arr_cat.push(‘’+rec1.category);
}
}
var total_sum = 0;
for (var i=0; i<arr_cat.length(); i++) {
var tempmult=1;
var rec2 = new GlideRecord(‘asmt_assessment_instance_question’);
rec2.addEncodedQuery(‘category=’+arr_cat[i]);
rec2.query();
while(rec2.next()){
tempmult = parseInt(rec2.value)*parseInt(tempmult);
total_sum = total_sum+tempmult;
}
}
gs.print(“The total sum”+total_sum);