Form field default value set by comparing the value of other fields

Sergio B. asked on January 5, 2018 13:35

How can I determine multiple possible default values of a field taking into account the values of two other fields in a form? For example, set the value of the field "Eval" to "Good" taking into account that another field "color" is "green" and a second field "Temperature" is "Hot", set the value of the field "Eval" to "Satisfactory" when field "color" is "orange" and "Temperature" is "Medium" and set the value of the field "Eval" to "Bad" when field "color" is "red" and "Temperature" is "Cold". I tried to solve the problem like this : {% Form.OnBeforeValidate += BeforeValidateHandler;%} {% if(color=="Green" && temperature=="Hot"){Form.Data.SetValue("Eval", "Good")};#%} {% if(color=="Orange" && temperature=="Medium"){Form.Data.SetValue("Eval", "Satisfactory")} else {Form.Data.SetValue("Eval", "Bad")};#%} Thank you for your help.

Recent Answers


Brenden Kehren answered on January 5, 2018 16:48

Your best bet for this is some javascript to auto-select/enter the value(s) you want. Using a macro will not work because the macro processing happens too early/late in the form processing.

But if you want only set values on submission then simply use the OnAfterSave event of the online form by either creating a custom webpart OR creating a global event handler for the form submission.

0 votesVote for this answer Mark as a Correct answer

Sergio B. answered on January 9, 2018 17:30

Thank you, Brenden. I'll do it this way.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.