• Resolved hotiday

    (@hotiday)


    Hello, I would like to use a custom function like a for loop in javascript to calculate the value of a field. Even a “summation” operation would be nice, but it seems impossible integrating something like this

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

    (@codepeople)

    Hello @hotiday

    Yes, you can use the code you prefer, including loops, conditional statements, and even calling third-party blocks of code. Please, describe the equation you are trying to implement and your code.

    Best regards.

    Thread Starter hotiday

    (@hotiday)

    I am trying to implement the following function:

    let i=1;
    let data = 16;
    let b = [];
    for(i =1;i<data+1;i++){
      let a = 10-0.0137039*i;
      a = Math.exp(a);
      b.push(a);
    }
    
    b = b.reduce((curr, more) => curr + more, 0)

    however I don’t know where do I find a custom block of code able to do this!

    • This reply was modified 3 years, 7 months ago by hotiday.
    Plugin Author codepeople

    (@codepeople)

    Hello @hotiday

    You should select the calculated field and enter the following piece of code through its “Set equation” attribute:

    (function(){
    let i=1;
    let data = 16;
    let b = [];
    for(i =1;i<data+1;i++){
      let a = 10-0.0137039*i;
      a = Math.exp(a);
      b.push(a);
    }
    
    return b.reduce((curr, more) => curr + more, 0);
    })()

    Best regards.

    Thread Starter hotiday

    (@hotiday)

    And what if I wany to set data = fieldname12? Do I have to put it out of the parenthesis?

    Plugin Author codepeople

    (@codepeople)

    Hello @hotiday

    Just replace the number 16 with the field name:

    (function(){
    let i=1;
    let data = fieldname12;
    let b = [];
    for(i =1;i<data+1;i++){
      let a = 10-0.0137039*i;
      a = Math.exp(a);
      b.push(a);
    }
    
    return b.reduce((curr, more) => curr + more, 0);
    })()

    Best regards.

    Thread Starter hotiday

    (@hotiday)

    Thank you very much, problem solved!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Custom function for calculated fields’ is closed to new replies.