5 Replies Latest reply on May 29, 2014 12:50 PM by gethappy@happypc.com

    drag and drop, then get focus?



      drag and drop, then get focus?


           we have a list layout with an externally stored (open) container field.  The layout simply shows a list of records each with one image and a few text fields.  We allow the user to drag and drop an image onto the container field.

           We are running into a problem if the user doesn’t FIRST select the record they are dragging the image on to.

           Basically  we have a script trigger on the container field with an “onObjectModify” trigger that sets the images FileName in a text field.

           So the user drags and drops, and the script immediately runs setting FileName to be “GetAsText(image)”.

           If the user is working on the selected record, everything works great.  The image gets stored and the field name is set correctly.

           The problem is when the user has a different record selected, the user drags and drops and the image stores correctly, but the focus is still on another record, so the set field command sets the text field in the wrong record to the wrong value.

           To use an example, let’s say the layout shows a list of 5 records, each record has one image and one text field.  If the currently selected record is the first one in the list, but the user drops the image onto the third record’s container field, the image is stored in record 3, but then as the ‘onmodify’ script gets triggered, it changes the fieldname text field on the first record to the file name of the first record’s container. 

           Ideally I want to find a way that when the user drags the image on the third record, the script selects that particular record (changes the focus) … and then changes the data on that record, but I can’t figure out how to do that.

           So … user drags onto the third record, image gets stored, context gets changed to record three, then set fields work correctly.

           The current situation is very confusing for the users, because they drag the image on a certain record and they see the image change … so they assume it is changing the correct data, but then another record’s data is changed instead.

           On a related note, I ran a test to see which script triggers fire, the only trigger that seems to work is “onObjectModify” … the other triggers never fire since I assume we technically never enter (or exit) the field.

           Any suggestions on how to change the context/focus to the record that the image is actually stored in?

        • 1. Re: drag and drop, then get focus?

               You are correct that OnObjectModify is the only trigger tripped. The trick is to script a method that identifies the record number or primary key of the record just now modified so that your trigger performed script can make that record the current record--ie put the focus on the same record as that of the modified field.

               If I recall a previous discussion correctly, what you can do  is add a field that auto-enters the modification timestamp. This field will update when you drag and drop so your script can then find the record with the most recent timestamp in this field to make it the most recent record.

          • 2. Re: drag and drop, then get focus?

                 thank you so much for your reply!  

                 I just tried your suggestion and the modified timestamp doesnt set the correct record.  Same problem occurs.

                 List of 5 records, the first one has focus.  When you drag and drop onto record 3, the timestamp of record one is adjusted, but record 3 stays as is.

            • 3. Re: drag and drop, then get focus?

                   Yes, your OnObjectModify must find this record to make it the current record. Just adding the field is not enough to make this happen. You can use record sorting or a sorted relationship to find either:

                   The record with the most recent Modification timestamp


                   The record with a modification account name that matches the current user's account name with the most recent Modification timestamp.

                   The second option is useful if you might have several users all doing drag and drops at the same time.

                   Consider this relationship:

                   YourTable::cCurrentAcountName = YourTable2::ModificationAccountName

                   cCurrentAccountName is an unstored calculation field defined as: Get ( AccountName ). ModificationAccountName is a text field that auto-enters the modification account name. YourTable2 is a new Tutorial: What are Table Occurrences? of YourTable.

                   You can set up this relationship to be sorted by ModificationTimeStamp in descending order, making the record modified by the current user with the most recent modification timestamp the first related record.

                   YourTable2::PrimaryKey would then be the primary key of the record your script would then make into the current record or you can use: Set Field [YourTabl2::FileName ; getasText (Yourtable2::image) ] to set the file name without even making the record the current record.

              • 4. Re: drag and drop, then get focus?

                     Note also that FileName could be a calculation field that extracts the file name and then no script at all is needed.

                • 5. Re: drag and drop, then get focus?

                       Smooth like butter ... Thank you PhilModJunk.

                       Using a modifed timestamp, then I created a relationship showing all records sorted by this timestamp field, so when the user drags and drops the record becomes the first in the related records.  Then I simply go to related record to make this record the active record.  Now i can modify anything without issue.

                       I know there are lots of other options, like modifying the records within the relationship instead of using a GTRR, and might go that route instead, but for now this is exactly what I needed. 

                       thank you SO much for your help.