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

AshishKM
Kilo Patron
Kilo Patron

Hi @Hicham-dev ,

What's the question here, please explain the issue with script.

 

-Thanks,

AshishKMishra


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

Salut @AshishKM Je veux que lors que le champ u_estimatif est modifié, la fonction u_estimatif multiplier par le champ u_taux_de_r_ussite s'exucute et le resulatat s'affiche dans le champ u_estimatif_pond_r.

 

J'ai reussi avec une businnes Rules mais je n'arrive pas en ClientScript

Are you writing client script on table or catalog client script for any catalog item. 

minor update in client script in either case, the client script form has Field Name, select the field "u_estimatif" here and remove the if condition applied on "u_estimatif".  

AshishKMishra_0-1700495189488.png

let me know if it works for you

-Thanks,

AshishKMishra

 


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

Cela ne foncctionne toujouts pas mais maintenant j'ai une erreur seur mon formulaire.

 

Je vous est mis deux images en pieces jointe ( celle du formulaire et celle du ClientScript)