The nice thing about this approach to the problem is that you don’t need to add any additional information to the form itself. A lot of the disable rules that you might learn will involve checking the value of other fields on the form. In this case, we are going to use a form function to check a value in the database behind the scenes.
All you need to do then is setup the field that you want to make required. Be sure to check “Required” for the form field.
The key to using the Disable Rule attribute in the form designer is that you have to put in a conditional statement that will resolve to
true when you want the field to be disabled. It’s somewhat counterintuitive but basically
true = disabled and
false = enabled.
For this example, we want to figure out if the client is under the age of 18. If the client is under the age of 18, we want to enable the field and require that the clinician enter some data. If the client is over 18, we want to disable the field. So our statement should look something like this:
[[client_age]] > 18
[[client_age]] is under 18, the statement resolves to false, so the field will be enable. If the client is over 18, the statement resolves to true and the field will be disabled. Now we just need to get the client’s age.
getDataValue Form Function
getDataValue() function. It is used to get a value from a column in the database based on the value of another column in the same table. It takes five arguments, one is an optional conditional statement that we will not get into here. For our purposes, we need to supply it with 4 things:
- the table we want to get data from
- the column we will match on
- the column value we will match on
- the column value we want returned
myEvolv has a view called the
client_personal_view which contains a calculated column for the client’s age, so the work of calculating an age has been done for us already.
So to get the age of the client we are entering a service for, we call the function like this:
getDataValue('client_personal_view', 'people_id', keyValue, 'age')
Here we are saying, get the value in the
age column from the
client_personal_view table in the row where the value of
people_id column is equal to
client_id of our current client.
The full code for our disable rule is now:
getDataValue('client_personal_view', 'people_id', keyValue, 'age') > 18
Remember, the “>” and “<" signs are special characters so we have to use the ascii codes or else you will throw an error when the form loads in myEvolv.