• Resolved Asjad Aamir

    (@asjad492)


    Hi, Can you please tell what is issue in following statement as it is giving incorrect answer. If I remove other conditions and only use one, it gives correct answer.

    (function(){
    
    
    if (AND(fieldname6 == 'Buying additional residence', fieldname8 == 'Yes')) {
    
        if (fieldname7 < 40000) {
            return fieldname7*0;
        }
    
         else if (40000 < fieldname7 < 250000) {
    
        return (fieldname7-40000)*0.03;
    }
         else if (250000 < fieldname7 < 925000) {
        return SUM(250000*0.03,(fieldname7-250000)*0.08);
    }
    
    
    }
    
    })();
    
    
Viewing 15 replies - 1 through 15 (of 37 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    Thank you very much for using our plugin.

    This condition structure is incorrect:

    else if (40000 < fieldname7 < 250000) {

    The correct structure is:

    else if ( AND(40000 < fieldname7, fieldname7 < 250000 ) ) {

    The same problem is here:

    else if (250000 < fieldname7 < 925000) {

    The correct is:

    else if ( AND( 250000 < fieldname7, fieldname7 < 925000 ) ) {

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    Please check. now is not performing calculation

    (function(){
    if (AND(fieldname6 == 'First-time buyer', fieldname8 == 'Yes')) {
    if (fieldname5 < 425000) {
    return fieldname5*0;
    }
    else if (AND(425000 < fieldname5, fieldname5 < 625000)) {
        return SUM(425000*0,(fieldname5-425000)*0.05);
    }
    else if (AND(625000 < fieldname5, fieldname5 < 925000)) {
        return SUM(250000*0,(fieldname5-250000)*0.05);
    }
    else if (AND(925000 < fieldname5, fieldname5 < 1500000)) {
        return SUM(250000*0,675000*0.05,(fieldname5-9250000)*0.1);
    }
    else if (fieldname5 > 1500000) {
        return SUM(250000*0,675000*0.05,575000*0.1,(fieldname5-1500000)*0.12);
    }
    }
    
    if (AND(fieldname6 == 'Buying additional residence', fieldname8 == 'Yes')) {
      
    if (fieldname7 < 250000) {
    return fieldname7*0.03;
    }
    else if (AND(250000 < fieldname7, fieldname7 < 925000)) {
        return SUM(250000*0.03,(fieldname7-250000)*0.08);
    }
    
    else if (AND(9250000 < fieldname7, fieldname7 < 1500000)) {
        return SUM(250000*0.03,675000*0.08, (fieldname7-925000)*0.13);
    }
    else if (fieldname5 > 1500000) {
        return SUM(250000*0.03,675000*0.08, 575000*0.13, (fieldname7-1500000)*0.15);
    }
    }
    
    if (AND(fieldname6 == 'Replacing your main residence', fieldname8 == 'Yes')) {
    
    if (fieldname5 < 250000) {
    return fieldname5*0;
    }
    else if (AND(250000 < fieldname5, fieldname5 < 925000)) {
        return SUM(250000*0,(fieldname5-250000)*0.05);
    }
    else if (AND(9250000 < fieldname5, fieldname5 < 1500000)) {
        return SUM(250000*0,675000*0.05, (fieldname5-925000)*0.10);
    }
    else {
        return SUM(250000*0,675000*0.05,575000*0.10,(fieldname5-1500000)*0.12);
    }
    }
    
    if (AND(fieldname6 == 'First-time buyer', fieldname8 == 'No')) {
    if (fieldname5 < 425000) {
    return fieldname5*0.02;
    }
    else if (AND(425000 < fieldname5, fieldname5 < 625000)) {
        return SUM(425000*0.02,(fieldname5-425000)*0.07);
    }
    else if (AND(625000 < fieldname5, fieldname5 < 925000)) {
        return SUM(250000*0.02,(fieldname5-250000)*0.07);
    }
    else if (AND(925000 < fieldname5, fieldname5 < 1500000)) {
        return SUM(250000*0.02,675000*0.07,(fieldname5-9250000)*0.12);
    }
    else if (fieldname5 > 1500000) {
        return SUM(250000*0.02,675000*0.07,575000*0.12,(fieldname5-1500000)*0.14);
    }
    }
    
    if (AND(fieldname6 == 'Buying additional residence', fieldname8 == 'No')) {
       
    if (fieldname7 < 250000) {
    return fieldname7*0.05;
    }
    else if (AND(250000 < fieldname7, fieldname7 < 925000)) {
        return SUM(250000*0.05,(fieldname7-250000)*0.10);
    }
    else if (AND(925000 < fieldname7, fieldname7 < 1500000)) {
        return SUM(250000*0.05,675000*0.1, (fieldname7-925000)*0.15);
    }
    else if (fieldname7 > 1500000) {
        return SUM(250000*0.05,675000*0.1, 575000*0.15, (fieldname7-1500000)*0.17);
    }
    }
    
    if (AND(fieldname6 == 'Replacing your main residence', fieldname8 == 'No')) {
    
    if (fieldname5 < 250000) {
    return fieldname5*0.02;
    }
    else if (AND(250000 < fieldname5, fieldname5 < 925000)) {
        return SUM(250000*0.02,(fieldname5-250000)*0.07);
    }
    else if (AND(925000 < fieldname5, fieldname5 < 1500000)) {
        return SUM(250000*0.02,675000*0.07, (fieldname5-925000)*0.12);
    }
    else if (fieldname5 > 1500000) {
        return SUM(250000*0.02,675000*0.07, 575000*0.12, (fieldname7-1500000)*0.14);
    }
    }
    })();
    
    
    
    Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    I’m sorry, but I don’t know the values of the fields. With the information provided, I can only check if the equation code does not contain parser errors. And I can confirm your current equation code is well structured. Now, you should check if the field values satisfy the conditions in the conditional statements in your equation.

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    Hi, thanks it worked. Now one more issue is that how to show speciifc number of fields based on number in previous field. So, as you can see in this link: https://www.gov.uk/hmrc-internal-manuals/stamp-duty-land-tax-manual/sdltm13080. If I enter number of years =4 in one number field, it should display 4 more fields in which I can enter value for each year,

    Thread Starter Asjad Aamir

    (@asjad492)

    Are you there?

    Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    You can create dependencies with radio buttons, checkbox, dropdown fields, and calculated fields. If the field you are referring to is a number field, you must use a calculated field as an auxiliary to configure the dependencies.

    Please, read the following post in the plugin blog:

    https://cff.dwbooster.com/blog/2020/03/01/dependencies

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    Let’s say I have slider field through which user selects number of years as 30 (let’s say). Now I want to automatically add 30 number of fields below it where user can enter amount for each field. How to do that?

    Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    The current plugin version does not generate fields at runtime. You must insert the maximum number of fields at the development time and activate or ignore them by coding.

    For example, assuming you have the number fields, fieldname1, fieldname2, fieldname3, fieldname4, fieldname5, and fieldname6, and the slider field is fieldname7.

    You can insert a calculated field in the form and enter the equation:

    (function(){
    var fields = [fieldname1|n, fieldname2|n, fieldname3|n, fieldname4|n, fieldname5|n, fieldname6|n];
    
    for(var i in fields){
        if(i<fieldname7) ACTIVATEFIELD(fields[i]);
        else IGNOREFIELD(fields[i]);
    }
    })()

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    What does n shows?

    Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    I have answered this question in at least two other of your forum threads.

    The plugin replaces the fields names with their values before evaluating the equations, the |n modifier tells the plugin you want to use the field’s name instead of its value.

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    Hi, so it worked. Now issue is I have set the setting of executing the calculated field when I press calculate button. So, is there any way that that field automatically executes without pressing calculate button?

    Thread Starter Asjad Aamir

    (@asjad492)

    Actually i HAVE two calculated fields. One of them I want to execute without pressing calculate button.

    Plugin Author codepeople

    (@codepeople)

    Hello @asjad492

    In the current version of the plugin, the dynamic evaluation of the equations affects every calculated field in the form. You cannot configure some equations with dynamic evaluation and other manuals.

    If you want the equations to be evaluated dynamically, you must tick the “Dynamically evaluate the equations associated with the calculated fields” checkbox in the “Form settings” tab.

    Best regards.

    Thread Starter Asjad Aamir

    (@asjad492)

    Hi, as far I know, in last thread, you suggested to write in HTML and gave me a script code to bypass restriction of dynamic evaluation. So, how to write that for loop code in html? link for related thread: https://www.ads-software.com/support/topic/hide-and-show-fields/

    Thread Starter Asjad Aamir

    (@asjad492)

    I tried to write this as you suggested in last thread:

    <script>
    	fbuilderjQuery(document).one('showHideDepEvent', function(evt, form_id){
    
    var f = jQuery('[name="cp_calculatedfieldsf_id"][value="7"]').closest('form');  
    
      
    jQuery(f).on('change', '[id*="fieldname11_"]', function(){
    	var fields = [fieldname13, fieldname14, fieldname15];
    
    for(var i in fields){
        if(i<fieldname11) ACTIVATEFIELD(fields[i]);
        else IGNOREFIELD(fields[i]);
    }
    });
    		jQuery('[id*="fieldname11_"]', f).change();
    });
    </script>
    
Viewing 15 replies - 1 through 15 (of 37 total)
  • The topic ‘Using if else statement’ is closed to new replies.