8 Replies Latest reply on Jun 2, 2011 3:44 PM by philmodjunk

    Setting a variable from a value list

    robdownunder

      Title

      Setting a variable from a value list

      Post

      G'day all,

      I have a need to set a variable based on a value list.

      You'll probably jump in and suggest to use a global field to capture the input from the layout, which works fine, until there are no visible records.

      In the scenario I have, I'm using the user input from the value list to extend the found records STARTING FROM 0 RECORDS, and I can't set the field to a non-existent record.

      I'd like to go straight from a value list to a variable.

      Can this be done ?

      I'm thinking I'll have to make the input a button that opens a new window with a stripped down layout displaying a record's value listed field. I'd then set a global variable from the selected field's input.  Any simpler solutions ?

        • 1. Re: Setting a variable from a value list
          philmodjunk

          A global field will work even when there are 0 records in your found set. You can format it with a value list and attach a script trigger to perform a script after a value is entered or selected if you need to.

          • 2. Re: Setting a variable from a value list
            aammondd

            Phil that is if your global field is on a table where there are records.

            If  the global field were on a temp table (ie his found set) where there are no records yet it wont work. Thats why I always put my Global fields in their own tables and ensure I have a single blank record in those tables at startup.

            Its an oddity that you can set a global field when there are no records in the table but you cant then subsequently use it for anything. (At least that has been my experience)

             

             

            • 3. Re: Setting a variable from a value list
              philmodjunk

              On the contrary, the global fields from a different table are also still editble. I just checked on one of my DBs to be sure. Wink

              • 4. Re: Setting a variable from a value list
                aammondd

                Yes you can edit them I agreed

                But they dont behave as you would expect when you reference  them for something. Whenever I use a Global field as a portal display key and I set it when there are no records in that global field's table it doesnt work to display the records in the portal.

                 

                 

                • 5. Re: Setting a variable from a value list
                  philmodjunk

                  Yes, it won't work to display data in a portal as your portal relationship will require a current record for the layout, but it will work to drive a triggered script--say to find records or to set a value used in auto-enter calculations for each new record.

                  • 6. Re: Setting a variable from a value list
                    aammondd

                    Ok I get what you are saying I modified my OnObjectModify script trigger on a global field to set another global field (in the same table) and then wrote a button script to pull the Global field values into a dialog box (even though there were no Global Field table records) it worked as you stated this is good to know.

                    • 7. Re: Setting a variable from a value list
                      robdownunder
                      Phil, I was doing exactly what you wrote in the first reply, but I had no luck at all getting a subsequent 'extend found set' step to find anything. With one record visible it worked fine, with no records visible it always failed. I've changed the way I deal with the problem now, so can't go back to re-test. I spent too much time on the problem and needed to move on. If I see this again I will try to make up some sample code to share. I'm wondering if it could be that when you have 1+ records visible, you don't need to force a commit, but when there are 0 visible, you do have to force a commit before you can use the field. Thanks.
                      • 8. Re: Setting a variable from a value list
                        philmodjunk

                        I just did the following:

                        1. Placed a global date field on the layout.
                        2. Copied the date from a different date field on the layout.
                        3. Used Show All Records | Show Omitted Only to get a found set of zero records
                        4. Pasted the copied date into the global field.
                        5. Ran this script:

                        Enter Find Mode []
                        Set Field [Table::DateField ; Table::GlobalDateField]
                        Extend Found Set []

                        It worked without any trouble to find all records with the date I pasted into the global field.