10 Replies Latest reply on Aug 16, 2013 9:45 AM by Vicky

    Lock drop down or pop up menu

    Vicky

      Title

      Lock drop down or pop up menu

      Post

           Hi,

           I have a lock field with the calculation If ( IsEmpty(Factory) ; 0 ; 1 ) and a script on the Factory field.

           If [ Evaluate ( Get ( ActiveFieldTableName ) & "::Lock" ) = 1 ]

             Revert Record / Request [ No dialog ]

           End If

           When Factory is just a normal edit box and the script trigger is OnObjectModify, Factory field is locked and works just like I want it to.

           However I wish to have a pop- up menu for factory or a drop down list ,but the lock does not work.  It just seem to delete the new record.  How should the script be changed in order for Factory to be locked after the user makes their initial selection from the value list.

        • 1. Re: Lock drop down or pop up menu
          philmodjunk

               Revert should delete the new record if it has never been committed. This should be the case regardless of the format used for the field.

          • 2. Re: Lock drop down or pop up menu
            Vicky

                 I don't know.  When it's just an edit box and I try to change the value, it won't let me but the record does not get deleted at all.  Is there any way to make the lock work with a value list?

            • 3. Re: Lock drop down or pop up menu
              philmodjunk

                   My point is that it IS working, just not the way that you want. Can you explain more fully what you are trying to accomplish here?

              • 4. Re: Lock drop down or pop up menu
                Vicky

                     Field is either a pop up box or a drop down list (which ever works better) with a value list called Factory.  I am trying to make it so that the user can select from the value list only once. After they click outside of the list, the factory they choose will not change if they try to select from the list again. 

                • 5. Re: Lock drop down or pop up menu
                  philmodjunk

                       Revert reverts all fields since the last time the record was committed. If this is a new record that has never been committed, the entire record will be reverted and all data entry is lost.

                       I suggest a different approach to making this a "select only once" field.

                       The OnObjectEnter script trigger can capture the original value of the field if you put a reference to that field in the optional script parameter box. In your case, you can put: YourTable::Factory as the parameter passed to this trigger's script. The script would then be:

                       Set Variable [$$OldValue ; value: Get ( ScriptParameter ) ]

                       Then you can use a second script parameter: (OnObjectModify for pop up menus or OnObjectSave for drop down lists) to perform this script:

                       If [Not IsEmpty ( $$OldValue ) ]
                          Set Field [ YourTable::Factory ; $$OldValue ]
                       End IF

                       If you want to make the reference to Factory in this script indirect (only needed if you place this field on more than one layout and some layouts refer to a different table occurrence), you can pass the table occurrence and field names as a parameter: GetFIeldName ( YourTable::Factory ) and then use:

                       Set Field By Name [ Get ( ScriptParameter ) ; $$OldValue ]

                       Note: the reason for using GetFIeldName like this is that if you later rename either the table occurrence or the field, this function will still return the correct names for use by Set FIeld By Name.

                  • 6. Re: Lock drop down or pop up menu
                    Vicky

                         Thank you for your response Phil!

                         I'll try out your suggestion.

                         I managed to get a lock to work and I would really like to know what you think.

                         I wrote this script and used OnObjectEnter on the pop up menu.

                         If [ Evaluate ( Get ( ActiveFieldTableName ) & "::Lock")=1]

                             Show Custom Dialog ["Select Factory" ; "Do you wish to select this factory?"]  // 1.Yes    2. No

                         End If

                         If [ Get (LastMessageChoice) = 1 ]

                            Commit Records/Requests []

                         Else

                             Revert Record/ Request [] 

                         End If

                    • 7. Re: Lock drop down or pop up menu
                      philmodjunk

                           It works, the problem with OnObjectEnter and the pop up menu is that the value selection from the menu is handled before onObjectEnter performs the script--hence the need to revert.

                           The main possible draw back to your script is that revert record could revert more data than the data in the factory field.

                      • 8. Re: Lock drop down or pop up menu
                        Vicky

                             Thank you for your help Phil!  It's ok if it reverts more data.  I was trying to lock that field to prevent users from adding additional lines into a portal.  Not completely foolproof since they can just keep clicking yes and add more into the portal, but I'll keep working on it and try to find a way to prevent lines from being added to the portal.

                        • 9. Re: Lock drop down or pop up menu
                          philmodjunk

                               You can set up a validation rule on fields in the portal that reject all input if a value in the parent record is set.

                               And The OnObjectScript Trigger can be set on the portal to check this value and use commit records to deny access to the portal.

                          • 10. Re: Lock drop down or pop up menu
                            Vicky

                                 Thank you for your advice! I don't really understand how the validation rules work on filemaker, so I'll go read up on it now and experiment.

                                 :)