• Resolved javahat

    (@javahat)


    Currently, the only conditions available are to show fields. Is there a way to create a custom calculation based on a value? For instance, I am creating a pricing calculator. I would like to create a field that has a different calculation based on another field. So, if the user has less than 100 employees, the formula would be employees * X. If they have between 200-350 employees, the calculation would be employees * Y. If they have between 350-500 employees, the calculation would be employees * z.

    I have gotten around this by creating a field for each price point and another field for each calculation. Then I have a dynamic field that uses dependencies to only shows the fields based on the number of users. However, this requires a lot of fields, and it makes it impossible to sum up multiple fields. For instance, a base price, plus the cost of employees.

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @javahat

    Thank you very much for using our plugin. The process is really simple. You can create an equation with conditional statements (if) or conditional operations (IF). The code is case-sensitive, please do not confuse them.

    So, you can implement the equation as follows:


    (function(){
    if(fieldname1 < 100) return fieldname1*10;
    if(fieldname1 < 350) return fieldname1*15;
    if(fieldname1 < 500) return fieldname1*20;

    return fieldname1*30;
    })()

    In the previous example, the values and field’s name are hypothetical.

    Best regards.

    Thread Starter javahat

    (@javahat)

    Wow, Thanks for such a quick response! I actually figured it out and was coming to comment on how I figured it out, but you beat me to it.

    One more question… If you have a check box with multiple options selected, how do you use conditional logic if one of the options is checked?

    Plugin Author codepeople

    (@codepeople)

    Hello @javahat

    Assuming you have a checkbox field fieldname1 with three choices, choice A with value 1, choice B with value 2, and choice C with value 3. By default, the plugin treats the field’s value as the sum of ticket choices. So, if the user ticks the checkbox choices A and B, the field value would be 3. However, you can use the field’s name in the equation with the |r modifier to access its raw field’s value. In this case, the plugin will manage it as an array with the values of the ticked choices. In the same case where the user selected the choices A and B, using fieldname1|r in the equation, the value would be the array [1,2], and you can use it with the “IN” operation.

    Hypothetically, if you want sum 10 to the feldname1 if choice A is in the list of ticked choices, sum 15 if choice B is in the list of ticked choices, and sum 20 if choice C is in the list, you can implement the equation as follows:


    (function(){
    let result = fieldname1;
    if(IN(1, fieldname1|r)) result = result+10;
    if(IN(2, fieldname1|r)) result = result+15;
    if(IN(3, fieldname1|r)) result = result+20;

    return result;
    })()

    Or if you simply want to add 10 per each ticked choice, the equation can be implemented as follows:

    fieldname1+10*fieldname1|r.length;

    Best regards.

    Thread Starter javahat

    (@javahat)

    Thank you for such a quick response.

    I sort of understand how to use your solution if I were calculating the total sum. It isn’t exactly what I am trying to do. You can see it in action at https://hrsoftware.app/kbs-connector-pricing-calculator.

    I am working on the toggle version. I have checkbox at the top that lists each product. I can set each value to a number if that is easier?

    Option1: slice
    Option 2: sync
    Option 3: invoice

    If option 1 is not selected, I would like the “slice” monthly calculation to be set to 0, otherwise, I would like to calculate the price.

    Below is the calculation I have so far…but it only works if one option is toggled.

    Calculation Field 1

    (function(){
    let result = fieldname3;
    if(IN('slice', fieldname3|r)) result = 1;

    if(fieldname3<1) return PREC(fieldname1*0,2);
    if(fieldname1<1) return PREC(fieldname1*0,2);
    if(fieldname1>0 & fieldname1<100) return PREC(fieldname1*0.65,2);
    if(fieldname1>99 & fieldname1 <250 ) return PREC(fieldname1*0.55,2);
    if(fieldname1>249 & fieldname1 <500 ) return PREC(fieldname1*0.40,2);
    if(fieldname1>499 & fieldname1 <750 ) return PREC(fieldname1*0.35,2);
    if(fieldname1>749 & fieldname1 <1000 ) return PREC(fieldname1*0.22,2);
    if(fieldname1>999 & fieldname1 <2000) return PREC(fieldname1*0.15,2);
    if(fieldname1>1999 & fieldname1 <3500) return PREC(fieldname1*0.08,2);
    if(fieldname1>3499 & fieldname1 <5000) return PREC(fieldname1*0.05,2);
    if(fieldname1>4999 & fieldname1 <6500) return PREC(fieldname1*0.04,2);
    if(fieldname1>6499) return PREC(fieldname1*0.03,2);
    })();

    Calculation Field 2

    (function(){
    let result = fieldname3;
    if(IN('sync', fieldname3|r)) result = 1;

    if(fieldname3<1) return PREC(fieldname1*0,2);
    if(fieldname2==0) return PREC(fieldname2*0,2);
    if(fieldname2>0 & fieldname2<100) return PREC(fieldname2*1,2);
    if(fieldname2>99 & fieldname2 <200 ) return PREC(fieldname2*0.90,2);
    if(fieldname2>199 & fieldname2 <350 ) return PREC(fieldname2*0.75,2);
    if(fieldname2>349 & fieldname2 <500 ) return PREC(fieldname2*0.55,2);
    if(fieldname2>499 & fieldname2 <750 ) return PREC(fieldname2*0.5,2);
    if(fieldname2>749 & fieldname2 <1000 ) return PREC(fieldname2*0.45,2);
    if(fieldname2>999) return PREC(fieldname2*0.35,2);
    })();

    Calculation Field 3

    Calculation Field 3
    (function(){
    let result = fieldname3;
    if(IN('ar', fieldname3|r)) result = 1;

    if(fieldname3<1) return PREC(fieldname1*0,2);
    if(fieldname4==0) return PREC(fieldname4*0,2);
    if(fieldname4>0 & fieldname4<100) return PREC(fieldname4*0.85,2);
    if(fieldname4>99 & fieldname4 <250 ) return PREC(fieldname4*0.75,2);
    if(fieldname4>249 & fieldname4 <500 ) return PREC(fieldname4*0.65,2);
    if(fieldname4>499 & fieldname4 <750 ) return PREC(fieldname4*0.45,2);
    if(fieldname4>749 & fieldname4 <1000 ) return PREC(fieldname4*0.40,2);
    if(fieldname4>999 & fieldname4 <1250) return PREC(fieldname4*0.35,2);
    if(fieldname4>1249 & fieldname4 <1500) return PREC(fieldname4*0.3,2);
    if(fieldname4>1499 & fieldname4 <1750) return PREC(fieldname4*0.25,2);
    if(fieldname4>1749) return PREC(fieldname4*0.2,2);
    })();
    I
    Plugin Author codepeople

    (@codepeople)

    Hello @javahat

    The choices’ values are Slice Delivery, BambooHR Sync, and AR Invoices not slice or sync

    Javascript, the language used by browser is case-sensitive.

    Also, the and operator is the double ampersand && not &

    Note that the use of return instruction makes the comparison for an interval unnecessary.

    I don’t understand your equation because sometimes you check the fieldname3 values and others the fieldname1. Furthermore, the choices’ values in the fieldname3 are texts, not numbers. There is no sense comparing fieldname3 with 1.

    If you want to return 0 if no Slice Delivery choice is selected or make the calculations, the equation would be:


    (function(){
    if(AND(fieldname3, fieldname1)) {
    if(IN('
    Slice Delivery', fieldname3|r)) {
    if(fieldname1<100) return PREC(fieldname1*0.65,2);
    if(fieldname1 <250 ) return PREC(fieldname1*0.55,2);
    if(fieldname1 <500 ) return PREC(fieldname1*0.40,2);
    if(fieldname1 <750 ) return PREC(fieldname1*0.35,2);
    if(fieldname1 <1000 ) return PREC(fieldname1*0.22,2);
    if(fieldname1 <2000) return PREC(fieldname1*0.15,2);
    if(fieldname1 <3500) return PREC(fieldname1*0.08,2);
    if(fieldname1 <5000) return PREC(fieldname1*0.05,2);
    if(fieldname1 <6500) return PREC(fieldname1*0.04,2);
    return PREC(fieldname1*0.03,2);
    }
    }
    return PREC(0,2);
    })();

    Best regards.

    Thread Starter javahat

    (@javahat)

    Thank you! It works perfectly. This is a great plugin. I look forward to exploring it more. I also appreciate the super quick responses!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.