mandy
September 4, 2023, 4:58am
1
Hello,
I want to create a field based on the overall score, which is calculated the by multiplying two values together.
For example,
Question1 choice field -
A = 3
B = 2
C = 1
Question2 choice field -
A = 3
B = 2
C = 1
Overall Score = Question1 Score x Question2 Score
Then classify based on the Overall Score
If Overall Score <1 = Low
If Overall Score <6 = Medium
If Overall Score <9 = High
Thanks in advance.
Dear @mandy ,
Are the answers exactly the same? That way, you can try the following approach:
var scores = {'Item A': 3, 'Item B' : 2, 'Item C' : 1 };
function calculateScore(){
var score = 0;
if(fd.field('Choice1').value){
score += scores[fd.field('Choice1').value];
}
if(fd.field('Choice2').value){
score *= scores[fd.field('Choice2').value];
}
fd.field('Rating').value = score;
}
fd.spRendered(function(){
calculateScore();
fd.field('Choice1').$on('change', function(){
calculateScore();
});
fd.field('Choice2').$on('change', function(){
calculateScore();
});
})
I've reproduced it here - CalcScore
mandy
September 4, 2023, 8:07pm
3
Thanks, @Nikita_Kurguzov . Can you do one more field to show the following? Thank you!
If Overall Score <1 = Low
If Overall Score <6 = Medium
If Overall Score <9 = High
Dear @mandy ,
I don't get the exact value ranges for the overall score, but you can try the following approach:
var scores = {'Item A': 3, 'Item B' : 2, 'Item C' : 1 };
function calculateScore(){
var score = 0;
if(fd.field('Choice1').value){
score += scores[fd.field('Choice1').value];
}
if(fd.field('Choice2').value){
score *= scores[fd.field('Choice2').value];
}
fd.field('Rating').value = score;
if(score >= 7){
fd.field('Overall').value = 'High';
}
else if(score >= 3){
fd.field('Overall').value = 'Medium';
}
else{
fd.field('Overall').value = 'Low';
}
}
fd.rendered(function(){
fd.field('Rating').disabled = true
fd.field('Overall').disabled = true;
calculateScore();
fd.field('Choice1').$on('change', function(){
calculateScore();
});
fd.field('Choice2').$on('change', function(){
calculateScore();
});
})