Applying Dependency for Calculated Fied
-
Hi, I have one field of drop down options and multiple calculated fields. Now, I want that if I select one of the options in a drop down, it only shows a specific calculated field and does not show other calculated fields. How to do that?
-
Is this correct?
(function(){
if(AND(fieldname8 == ‘Buy Online’, fieldname10 == ‘Great Britain’)){
return SUM(fieldname5*15,10); } else if(AND(fieldname8 == ‘Alternative payment method’, fieldname10 == ‘Great Britain’)){ return fieldname5*2;
}
})()Hello @asjad492
I don’t know the names of the fields in your form or their choices’ values, but the equation’s structure is correct. It does not contain parser errors.
Best regards.
Thank you so much. It worked like a charm. You’re such a great person:)
Hi, I used this code now:
(function(){ if(AND(fieldname8 == 'Buy Online', fieldname10 == 'EEA')){ return fieldname6*0.00; } else if(AND(fieldname10 == 'Great Britain')){ return SUM(fieldname6*0,fieldname6*0.0129); } else if(AND(fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0,fieldname6*0.0199); } else if(AND(fieldname10 == 'All other countries')){ return SUM(fieldname6*0,fieldname6*0.0299); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'EEA')){ return SUM(fieldname6*0.024,0.35); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.024,SUM(fieldname6*0.0129,0.35)); } })()
Now, the issue is when I select Alternative payment method and Great Britain from drop-down, it does not give correct value for this one.
Hello @asjad492
When you use multiple conditional statements, you must enter them from more specific conditions to most general.
For example, if you have the conditional statement:
} else if(AND(fieldname10 == 'Great Britain')){
before
} else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){
The second conditional statement is never reached because the first one satisfy the same condition and appears first.
Best regards.
So, for
else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.024,SUM(fieldname6*0.0129,0.35))
it is giving same value as
else if(AND(fieldname10 == 'Great Britain')){ return SUM(fieldname6*0,fieldname6*0.0129);
How to overcome this problem?
Hello @asjad492 When you use multiple conditional statements, you must enter them from more specific conditions to most general. For example, if you have the conditional statement: } else if(AND(fieldname10 == 'Great Britain')){ before } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){ The second conditional statement is never reached because the first one satisfy the same condition and appears first. Best regards.
Hello @asjad492
You did not understand me explanation. For example, if you enter the equation:
(function(){ if(AND(fieldname8 == 'Buy Online', fieldname10 == 'EEA')){ return fieldname6*0.00; } else if(AND(fieldname10 == 'Great Britain')){ return SUM(fieldname6*0,fieldname6*0.0129); } else if(AND(fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0,fieldname6*0.0199); } else if(AND(fieldname10 == 'All other countries')){ return SUM(fieldname6*0,fieldname6*0.0299); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'EEA')){ return SUM(fieldname6*0.024,0.35); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.024,SUM(fieldname6*0.0129,0.35)); } })()
Now, suppose the user selects the options ‘Alternative payment method’ for the fieldname8, and ‘Great Britain’ for fieldname10.
Javascript checks every condition from top to bottom:
fieldname8 == 'Buy Online'
is false. So, javascript check the second condition:fieldname10 == 'Great Britain'
is true. So, in this case, javascript evaluates thereturn SUM(fieldname60,fieldname60.0129);
line of code, and returns the equation’s result, and the rest of instructions are simply ignored.For this reason, you must move the more specific conditions (like
} else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){
) at the top of the equation.Best regards.
Thanks for such a detailed explanation. It worked.
Is there any way to convert this complete table into German Language?
Hello @asjad492
You can clone the form from the plugin configuration page by pressing the “Clone” button, and translate the cloned form texts. Finally, insert the form in German, or any other language, on the appropriate pages of the website.
Best regards.
Hi, I’m facing one more issue. Please check this video: https://www.loom.com/share/32f1adf231a5487ba59a31b70668bbdc
This is the code
(function(){ if(AND(fieldname8 == 'Buy Online', fieldname10 == 'EEA')){ return fieldname6*0.00; } else if(AND(fieldname8 == 'Buy Online', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0,fieldname6*0.0129); } else if(AND(fieldname8 == 'Buy Online', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0,fieldname6*0.0199); } else if(AND(fieldname8 == 'Buy Online', fieldname10 == 'All other countries')){ return SUM(fieldname6*0,fieldname6*0.0299); } if (AND(fieldname8 == 'Alternative payment method', fieldname10 == 'EEA')){ return SUM(fieldname6*0.024,0.35); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.0369,0.35); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0199,0.35)); } else if(AND(fieldname8 == 'Alternative payment method', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } else if(AND(fieldname8 == 'QR code transaction of at least 10,01 EUR', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.005,SUM(fieldname6*0.0299,0.1)); } else if(AND(fieldname8 == 'QR code transaction of at least 10,01 EUR', fieldname10 == 'EEA')){ return SUM(fieldname6*0.005,SUM(fieldname6*0,0.1)); } else if(AND(fieldname8 == 'QR code transaction of at least 10,01 EUR', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.005,SUM(fieldname6*0.0129,0.1)); } else if(AND(fieldname8 == 'QR code transaction of at least 10,01 EUR', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0.05,SUM(fieldname6*0.0199,0.1)); } else if(AND(fieldname8 == 'QR code transaction up to 10,00 EUR', fieldname10 == 'EEA')){ return SUM(fieldname6*0.01,SUM(fieldname6*0,0.05)); } else if(AND(fieldname8 == 'QR code transaction up to 10,00 EUR', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.01,SUM(fieldname6*0.0129,0.05)); } else if(AND(fieldname8 == 'QR code transaction up to 10,00 EUR', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0.01,SUM(fieldname6*0.0199,0.05)); } else if(AND(fieldname8 == 'QR code transaction up to 10,00 EUR', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.01,SUM(fieldname6*0.0299,0.05)); } else if(AND(fieldname8 == 'Invoice purchase with Ratepay', fieldname10 == 'EEA')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0,0.35)); } else if(AND(fieldname8 == 'Invoice purchase with Ratepay', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0129,0.35)); } else if(AND(fieldname8 == 'Invoice purchase with Ratepay', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0199,0.35)); } else if(AND(fieldname8 == 'Invoice purchase with Ratepay', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } else if(AND(fieldname8 == 'Invoice purchase with Ratepay', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } else if(AND(fieldname8 == 'All other business transactions', fieldname10 == 'EEA')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0,0.35)); } else if(AND(fieldname8 == 'All other business transactions', fieldname10 == 'Great Britain')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0129,0.35)); } else if(AND(fieldname8 == 'All other business transactions', fieldname10 == 'USA & CANADA')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0199,0.35)); } else if(AND(fieldname8 == 'All other business transactions', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } else if(AND(fieldname8 == 'All other business transactions', fieldname10 == 'All other countries')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } else if(AND(fieldname8 == 'Send and receive money (friends and family members)')){ return fieldname6*0; } else if(AND(fieldname8 == 'Donation through listed PayPal Fundraisers', fieldname15 == 'Northern Europe ')){ return SUM(fieldname6*0.0249,SUM(fieldname6*0.0299,0.35)); } })();
Hello @asjad492
I’m sorry, but the support service does not cover the implementation of the users’ projects. If you need we implement your project you should contact us directly through the plugin website:
https://cff.dwbooster.com/customization
However, I can give you some tips.
First, the SUM operation accepts multiple parameters. You don’t need to repeat the SUM operation by pairs of operands.
Instead of
SUM(fieldname6 * 0.0249, SUM(fieldname6 * 0.0199, 0.35));
you can useSUM(fieldname6 * 0.0249, fieldname6 * 0.0199, 0.35);
(I used the SUM operation only once, with three parameters)Second, when you define dependencies, the values of the disabled fields are treated as zero by the equations. So, their sum is not affected by the disabled fields.
Hypothetically, if you have two fields fieldname1 and fieldname2 configured as dependent on the choices of the dropdown field fieldname3. You don’t need to include conditional statements in the equation to know the choice ticked to use the fieldname1 or fieldname2. You simply should use their sum
SUM(fieldname1,fieldname2)
because only the active one will have a value different from zero.Finally, pay attention to the texts and values you entered in the choices of the fieldname15 field. You entered them with a tab symbol at the end (\t). Please, remove the tabs symbols and edit the equation to use the text only.
If you need to hire a developer to debug your form implementation, or implement your project, you should request a custom coding service directly in the plugin websites.
Best regards.
Hi every thing is almost done. One small thing, What is | n in below code?
(function(){ IGNOREFIELD(fieldname3|n); IGNOREFIELD(fieldname4|n); IGNOREFIELD(fieldname5|n); if(AND(fieldname1 == 'A', fieldname1 == 'C')){ ACTIVATEFIELD(fieldname5|n); } else if(AND(fieldname1 == 'A')){ ACTIVATEFIELD(fieldname3|n); } else if(AND(fieldname1 == 'B')){ ACTIVATEFIELD(fieldname4|n); } })()
- The topic ‘Applying Dependency for Calculated Fied’ is closed to new replies.