Join the Team Forms community

score survey

Updated 3 weeks ago

Hello everybody,

I'm trying to build a quality control form. So far so good with the form but I can't figure out how to add scoring to my form.



The build looks like this :



Each value is unique and I'd like to say :

if value options1 == Yes 1 point

Ifnot == 0 point


I tried to follow the following help https://help.teamforms.app/en/articles/9127420-calculating-a-score-based-on-users-response

But I don't understand under which tab I should put the formula and what to do in the API tab ?



So far my code looks like this :


Java
value = 
  (data.changersacpoubellesfixesmobiles === 'oui' ? 1 : 0 )
+ (data.ramasserdechetsvoiescirculation === 'oui' ? 1 : 0 )

and I have the following errors :

  • Property 'ramasserdechetsvoiescirculation' does not exist on type 'Data'

Java
This comparison appears to be unintentional because the types 'Record<"changersacpoubellesfixesmobiles" | "ramasserdechetsvoiescirculation" | "controlerEtNettoyerLesTachesDeLiquide" | "nettoyerLesTracesDhuileAuSol" | "nettoyerLesPlaquesDeSignalisation" | "nettoyerLesVoiesDeCirculationEtLesPlacesDeParking" | "nettoyerLesCirculationsPietonnesEnDallesEntreePersonnelEtVisiteurs" | ...' and 'string' have no overlap.(2367)



Thanks in advance !

Marked as solution

Hi Steve,

The instruction in the link you referenced is based on a form with multiple radio option so it will not necessarily work for your form which contains a survey component.

For a survey component where you would like to calculate a score based on the number of times "yes" is selected you can use the steps below.


  1. Drag and drop your survey component into your form and configure to options.

  2. Drag and drop a number component into your form. This will use "calculated values" to display a score based on a calculation

  3. For the number component, navigate to the data tab and add the following expression into the "calcualted value" setting. Note you will need to update the expression to match the field names and value used in your specific form.

    JavaScript
    let score = 0
    
    Object.keys(data.survey).forEach(key => {
        if(data.survey[key] === 'yes')
            score = score + 1
    })
    
    value = score


Here is an example of the output:


View full solution
E
S
1 comment·1 reply

Hi Steve,

The instruction in the link you referenced is based on a form with multiple radio option so it will not necessarily work for your form which contains a survey component.

For a survey component where you would like to calculate a score based on the number of times "yes" is selected you can use the steps below.


  1. Drag and drop your survey component into your form and configure to options.

  2. Drag and drop a number component into your form. This will use "calculated values" to display a score based on a calculation

  3. For the number component, navigate to the data tab and add the following expression into the "calcualted value" setting. Note you will need to update the expression to match the field names and value used in your specific form.

    JavaScript
    let score = 0
    
    Object.keys(data.survey).forEach(key => {
        if(data.survey[key] === 'yes')
            score = score + 1
    })
    
    value = score


Here is an example of the output:


Hi Erin,

Thanks it works perfectly !

Best regards