• Resolved denisa

    (@elenadenisa)


    Hi there,
    Can someone help me, pls?
    I can’t get a function to return the value on a calculaiton field.
    I have four fields:
    – nightly rate $ – fieldname 2
    – days fieldname6
    – years fieldname11
    – inflation fieldname7

    …and a calclation field fieldname12

    I have this function
    function () {
    day = fieldname2;
    days = fieldname6;
    years = fieldname11;
    rate = fieldname7;
    total = 0;
    temp = 0;
    price=day*days;

    for(var i = 1; i <= years; i++){
    price=calprice(price,rate)
    total=total+price;

    tf = fieldname12; tf.setValue(parseInt(total) + ‘$’);
    };

    and it’s not returning anything.

    Can you help me pls? What I’m doing wrong. I’m moving this and it doesn’t want to work here.
    Thank you for your time

    • This topic was modified 6 years, 8 months ago by denisa.
    • This topic was modified 6 years, 8 months ago by denisa.
    • This topic was modified 6 years, 8 months ago by denisa.
    • This topic was modified 6 years, 8 months ago by denisa.
    • This topic was modified 6 years, 8 months ago by denisa.
Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m a complete noob so this might not work but I have a function that is structured like this and it works for me. Not sure if the opening parenthesis makes a difference in this plugin but I pulled this syntax directly from their documentation.

    (function(){

    if(fieldname10 == 12)
    return prec(fieldname1*1.4,2);
    if(fieldname10 == 24 )
    return prec(fieldname1*1.6,2);
    if(fieldname10 == 36)
    return prec(fieldname1*1.8,2);

    })();

    • This reply was modified 6 years, 8 months ago by phixate.
    Thread Starter denisa

    (@elenadenisa)

    Hi @phixate,
    Thank you for your post, but mine is a for loop, not a conditional if statement,a nd it will not work. I’m not a pro also, so I’m sure that somewhere I miss something.
    Thank you anyway for trying to help me.

    Well, I tried! Hope you get it resolved.

    Thread Starter denisa

    (@elenadenisa)

    I’ve fixed the code, but I have a very simple issue now, and to tired to be able to get it work. I’ll open a new thread

    Plugin Author codepeople

    (@codepeople)

    Hello ,

    There are some errors in your code, actually the equation’s structure should be:

    
    (function(){
    })()
    

    To allow it be evaluated immediately.

    Second, there are many variables defined globally, and some semicolon symbols that were not included, and much more important, there is required a “return” instruction to return the result.

    A possible equation would be:

    
    (function () {
    	var day = fieldname2,
    	days = fieldname6,
    	years = fieldname11,
    	rate = fieldname7,
    	total = 0,
    	temp = 0,
    	price = day * days;
    
    	for (var i = 1; i <= years; i++) {
    		price = calprice(price, rate);
    		total = total + price;
    	};
    	
    	return PREC(total,2);
    })()	
    

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘java calculated field form’ is closed to new replies.