9 Replies Latest reply on Nov 30, 2011 9:39 AM by DavidLuscombe

    add to value list

    m10muhammad

      Title

      add to value list

      Post

      one table in my database includes two fields with value lists, manufacturer and model, where the latter depends on the former (i.e. the value list i get to choose from for model depends on the value i selected from the manufacturer list).

      sometimes, however, a new model comes out that is not on the pre-defined value list. i am wondering if it is possible that when i type in a model that is not on the value list, it would then add itself to the values for the value list.

      for example, if manufacturer is Heidelberg, i would get choices GTO50, GTO52, and GTO54 on my model value list. however a new model GTO56 came out, which is not on the value list. normally i would have to go to the table where i entered the model values, and add GTO56 along with the foreign key for manufacturer Heidelberg. 

      what i want to do is that when i override the value list and type in GTO56, it would then add itself to the value list so that the next time i select heidelberg as the manufacturer, i would have the option of selecting GTO56 as the model.

      please advise, thanks. 

        • 1. Re: add to value list
          philmodjunk

          You could write a script that checks the value just entered against the values in the value list. If it's not in the list, it can switch to the layout for your table of values, create a new record and enter the new value. The script can also ask you to confirm that you want to do this before doing it if you want. Set this script up with an onObjectExit script trigger and it'll check every value just after you enter it.

          • 2. Re: add to value list
            m10muhammad

            How would I write this script as in what steps would I include so that it checks the value entered against the values in the list?

            • 3. Re: add to value list
              philmodjunk

              Your "test line" in the script might look like this:

              Commit Record
              If [ IsEmpty ( FilterValues ( ValueListItems ( get ( Filename ) ; "YourValueListNameInQuotes" ) ; YourTable::YourField ) ) /* text entered is not in value list */]

              Notes: ValueListItems requires the name of your file and your value list. Using Get ( Filename ) insures that changing the name of your file doesn't cause this function to fail. If you later change the name of your value list, this function will return null and your script will treat every value as not being a member of the value list.

              Edit Note: I spotted an omission in the above expression just after committing the post, but then lost internet connectivity for nearly half an hour... :-(

              • 4. Re: add to value list
                m10muhammad

                I am having some difficulty writing this script properly. I would appreciate it if you could help me with this. 

                • 5. Re: add to value list
                  philmodjunk

                  What have you got so far and where are you having difficulty?

                  • 6. Re: add to value list
                    m10muhammad

                    Well first I selected Commit Records/Request which gave me the step Commit Records []

                    Then I selected If which gave me If []

                    In this step I specified IsEmpty ( FilterValues ( ValueListItems ( Get ( FileName ) ; "ModelITEM" ) ; Item::Model ) ) /* text entered is not in value list */

                    Now how would I ensure that a new model would add to the value list?

                    • 7. Re: add to value list
                      philmodjunk

                      If [IsEmpty ( FilterValues ( ValueListItems ( Get ( FileName ) ; "ModelITEM" ) ; Item::Model ) ) /* text entered is not in value list */]
                         Show Custom Dialog [Item::Model & " is not in the list. Add it?"] //name button 1 "Yes", button 2 "No".
                         If [ Get ( lastMessagechoice ) = 1 /* button one was clicked */ ]
                            Set Variable [ $NewModel ; value : Item::Model ]
                            Freeze window
                            Go To layout [//specify layout of value list table]
                            New Record/Request
                            Set Field [Yourvaluelisttable::Model ; $NewModel]
                            Go To Layout [Original Layout]
                         End IF
                      End If

                      • 8. Re: add to value list
                        m10muhammad

                        Thanks, worked like a charm!

                        • 9. Re: add to value list
                          DavidLuscombe

                          Hello.  I have been looking for a way to complete  this task & just stumbled on this.

                          Should this be a script or a calculation/ validation in the field name in 'manage'.

                          Also, when the new record has been created for the value list, will the new value still appear in the drop down on the original layout.

                          Many thanks