I have a drop-down field set up. There are 4 items in it. I'd like to add a script trigger so that if the item "No" is selected from the drop down, a certain field will lock so that no more edits can be made. Is this possible?
Figured it out. I just used Hide object and placed a duplicate field that was Find only.
Yes, you can do this. Just set an OnObjectEnter Script Trigger on the field you want to "lock" such that, if field "X" equals "No", just send the cursor to another field instead. You can couple it with a dialog telling the user that entry is prohibited if you like.
Be aware that this doesn't truly "lock" the record. Users can still import records into the database (importing ignores Script Triggers). Also, it will only work on a layout where the Script Trigger is installed, so if users have access to any other layouts, you will need to install the trigger there as well. Short version: This should not be relied on for any sort of absolute security.
yes, it is possible.
poor man's one:
- make a copy of the layout, select all fields, unckeck the Browse in inspector. No editable fields anymore.
- on the original layout, have a trigger OnLayoutEnter, which goes to the copy layout if the field = "no".
- create a privilege set with Edit Records limited to yourField ≠ "no"
Easier would be just not to show the other edit fields before something is chosen in your dropdown. Just hide field a, b or c or any combination. No script triggers needed for that.
Two big plus with this approach:
I don't know if any way to make that happen with a script trigger, but I think the same thought process could be accomplished by the new functionality of Hide Object when.
I would create a second set of fields on the layout that start out as hidden. I would set the hide object when setting to:
and then on the ones that already exist I would put the following command in the settings for that box.
not isEmpty ( 'fieldName' )
It accomplishes the same thing, but no script steps should be required for it.
I hope this makes sense. I use this type of thing to show and hide menus all of the time.
That's what I ended up doing. I hide 3 fields but place duplicates of the fields in the same position. Yes/No just switches the "Hide Object"
The gotcha to doing it this way would be that they could change that value to the other method and it will turn those fields back on for editing. I am not certain that this is what you would like them to do or not.
One BIG drawback to using "Hide" as security is that, if your user views the layout in Table view, any hidden data field is NOT hidden since Hide conditions are not evaluated in Table mode. Turn off the Table view in the layout options to further protect yourself a bit. BUT...
Scripts ignore the fact that an object is hidden. So let's say you put field FieldName on a layout, then duplicate it. In a very important script, you use a "Go to Field: FieldName" step. The script may end up going to the wrong occurrence of "FieldName". To be able to KNOW which occurrence you were going to, you'd have to name each object. Maybe...FieldName_Find and FieldName_Edit. Then you could go to Object instead of Go to Field. You'd be naming a lot of objects, and your layouts would be "heavier" because each object gets drawn, each hide condition gets evaluated, etc.
Just some things to think about.
Retrieving data ...