• Resolved oidamo

    (@oidamo)


    Hi,

    How can I use the result of a calculation as predefined value in another field (eg., number or single line text)?

    Thanks a lot in advance!

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

    (@codepeople)

    Hello @oidamo

    You can assign the values to the other fields from the calculated field’s equation.

    For example, assuming you have a calculated field with the equation: fieldname1+fieldname2 and you want to assign the result to the number field fieldname4

    You should edit the equation as follows:

    (function(){
    var result = fieldname1+fieldname2;
    getField(4).setVal(result);
    return result;
    })()

    The getField operation receives as a parameter the numeric part of the field’s name and returns an object representation of the field. The setVal method of this object assigns the field’s value.

    In the equation above, I calculate the sum, assign it to the fieldname4, and finally, I return the result to the calculated field.

    Best regards.

    Thread Starter oidamo

    (@oidamo)

    Thanks a lot for your quick reply, your equation worked like a charm.

    I’m using “,” as a decimals separator symbol but the return in fieldname4 has “.” as seperator. How can I change this?

    Plugin Author codepeople

    (@codepeople)

    Hello @oidamo

    Please, edit the equation as follows:

    (function(){
    var result = fieldname1+fieldname2;
    getField(4).setVal(FORMAT(result, {decimalsymbol:","}));
    return result;
    })()

    Best regards.

    • This reply was modified 3 years ago by codepeople.
    Thread Starter oidamo

    (@oidamo)

    I already tried this but it does not work. The return field (fieldname4) is not a calculation field but a number field because I want the user to have the possibility to override the result of the calculation. Is this the problem?

    Plugin Author codepeople

    (@codepeople)

    Hello @oidamo

    Please, look at the equation I sent you previously:

    (function(){
    var result = fieldname1+fieldname2;
    getField(4).setVal(FORMAT(result, {decimalsymbol:","}));
    return result;
    })()

    Note the use of the FORMAT operation.

    If the previous equation does not format the value in the way you want, please, send me the link to the page where the form is inserted to check the settings of the fieldname4 field.

    Best regards.

    Thread Starter oidamo

    (@oidamo)

    The equation worked, thanks for your help!

    One more question: How can I return the text a user entered into a single line text field into another single line text field?

    • This reply was modified 3 years ago by oidamo.
    Plugin Author codepeople

    (@codepeople)

    Hello @oidamo

    The process is the same, assuming you want to set the value entered by the user through the fieldname1 into the fieldname2. Insert a calculated field with the equation:

    getField(2).setVal(fieldname1|r);

    And that’s all.

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Using result of a calculation as predefined value in another field’ is closed to new replies.