How to get value of multiplication of 2 integer fields

akshayp
Tera Expert

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

1 ACCEPTED SOLUTION

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

View solution in original post

6 REPLIES 6

RaghavSh
Kilo Patron

try below:

 

var a = 1;

var asmt= new GlideRecord('asmt_assessment_instance_question');
asmt.addEncodedQuery('instance=41c5ebfe1bbb5110c1cb4197dc4bcb6f^category=d7d0b13f1b359910c1cb4197dc4bcbbb');
asmt.query();
while(asmt.next())

{
a = pareInt(asmt.value)*parseInt(a);
}

gs.print(a);


Raghav
MVP 2023

ya , its working 

Thanks a lot!

 

if possible, can you please help me for 1 advanced logic

Like , i got the value for 1 specific category as per encoded query, now i want values for all categories and then i want only one value which will be sum of all values,

can you help a bit for that?

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