ClientsCRIPT OnChange NE FONCTIONNE PAS

Hicham-dev
Tera Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    // Vérifiez si le champ modifié est 'Estimatih HT'
    if (control == 'u_estimatif') {
        calculateAndSetC();
    }

    function calculateAndSetC() {
        // Récupérer les valeurs des champs 'u_estimatif' et 'u_taux_de_r_ussite'
        var valueA = g_form.getValue('u_estimatif');
        var valueB = g_form.getValue('u_taux_de_r_ussite');

        // Effectuer le calcul
        var result = (parseFloat(valueA) * parseFloat(valueB)) / 100;

        // Définir le résultat dans le champ 'u_estimatif_pond_r'
        g_form.setValue('u_estimatif_pond_r', result);
    }
}
2 ACCEPTED SOLUTIONS

Depending on the field types, you will want to use with "getDecimalValue" (probably) or "getIntValue" to retrieve the value of the fields as numbers and then do your calculation.  The problem is parseFloat is tripping up on the space between "10" and "000" and only returning 10 as the result in your example.  So (50 * 10) / 100 = 5

View solution in original post

The field type should be same for all 3 variable. 

u_estimatif ,u_taux_de_r_ussite,u_estimatif_pond_r

 

add the replace() method and try again. 

 

var valueA = g_form.getValue('u_estimatif').replace(/,/g,'');

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

View solution in original post

12 REPLIES 12

Correct the variable name.

 

AshishKMishra_0-1700497199551.png

-Thanks,

AshishKMishra

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Désolé c'etait une erreur de ma part, cela fonctionne mais le calcul n'est pas bon. je vous est mis un exemple en piece jointe et sur 10 000 au lieu d'avoir 1000 le resultat et 1 car je pense que comme le champ est 10 000  et non 10000 il prends que le 10

Depending on the field types, you will want to use with "getDecimalValue" (probably) or "getIntValue" to retrieve the value of the fields as numbers and then do your calculation.  The problem is parseFloat is tripping up on the space between "10" and "000" and only returning 10 as the result in your example.  So (50 * 10) / 100 = 5

@Jim Coyne merci pour votre aide 

maintenant cela fonctionne correctement