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.
2 thoughts to “How To: Make a Field Required Based on Client Age”
Thank you for all of the information! It has been extremely helpful. I have a question. I have been trying to use the code you provided to keep a form open after save, but it is just not working. My code matches yours perfectly, and I am putting in the correct place. Any ideas why this isn’t working?
I looked on the Netsmart wiki and their article has more involved code for keeping a window open after save. In looking at the code they show, I don’t understand what purpose most of it serves. It seems like the
window.closeAfterSave = false;bit is the critical piece (especially since that is all I have ever needed to use) but maybe adding the rest of the code will help get it working in your situation.
Go on the wiki, filter it to the myEvolv solution and look for an article called “Modifying a Form to Close when Saved”. If that doesn’t work for you, I would need some more information or even be able to screenshare with you to have a better idea of what might be going on.
Let me know how it goes!