6 Replies Latest reply on Oct 22, 2012 2:24 PM by philmodjunk

    Record to Modal, back to Record...

    brian.curran

      Title

      Record to Modal, back to Record...

      Post

           Hi,
           I have a layout for contacts called 'People':

           All the fields on the layout are non-Browse to prevent accidental editing. Two buttons (New and Edit) open up a Modal window for editing purposes. 

           After clicking the 'Save' or 'Cancel' button, I want to return the user to the original record they were browsing so I tried the script shown below for the 'Save' button:

           Commit Records/Requests []
           Set Variable [$$id; Value:People::__kpPeopleID]
           Close Window [Current Window]
           Adjust Window [Maximise]
           Refresh Window [Flush cached join results]
           Set Field [People::__kpPeopleID; $$id]

           This appeared to work yesterday but I've just noticed that duplicate values have appeared in the People tables primary key. I've changed this to disallow duplicate values but now the above script won't work.

           Any suggestions?

           Thanks
           Brian.

        • 1. Re: Record to Modal, back to Record...
          brian.curran

               Ah, I've deleted the last line and replaced it with:
               Perform Find (Restore) with a criteria of People::__kpPeopleID=$$id

               This seems to work fine but it's narrowing down to a found set of 1 instead of showing all but going to the correct record. Is there a better way to accomplish this?

               Thanks
               Brian.

          • 2. Re: Record to Modal, back to Record...
            philmodjunk

                 How do you open the window for editing in the first place?

                 Isn't the original window already displaying the record that you are editing?

                 I would think that you just need to close the modal window. (And you don't need to commit records before closing the window either.)

            • 3. Re: Record to Modal, back to Record...
              brian.curran

                   Hi Phil,
                   To open the Modal window, I can use a 'New' button or an 'Edit' button. The script shown below is to create the 'New' record

              • 4. Re: Record to Modal, back to Record...
                philmodjunk

                     Ok, the key missing detail is that your script is creating a new record, not opening an existing record for editing.

                     If your found set in the original window was all records, you can modify your script like this:

                     Set Variable [$$id; Value:People::__kpPeopleID]
                     Close Window [Current Window]
                     Adjust Window [Maximise]
                     Enter Find Mode []
                     Set Field [People::__kpPeopleID; $$id]
                     Perform Find[]
                     Show All records

                     If the found set in your original window was not all records, you should repeat whatever operation produced that found set and then your script can loop to the specified record checking ID's with each iteration of the loop.

                • 5. Re: Record to Modal, back to Record...
                  brian.curran

                       Hi Phil,
                       Sorry I should have explained it better, the script I posted above was for the 'New' button. The 'Edit' button uses a duplicate script except for the last line (New Record/Request), which is missing.

                       The ID in the People table is set to be generated 'On commit', which is why I thought I would need the Commit Records script step. I set it up like this as 'reverting a record' didn't delete the blank row in the table.

                       Just tried your script and it works perfectly when the original window was ALL records. I'm not sure what you mean when using a found set though, it seems to work fine except that my found set of 3 records displays all records when the original window returns. This is perfect for me though...

                       Thanks
                       Brian.

                        

                  • 6. Re: Record to Modal, back to Record...
                    philmodjunk

                         In cases where you edit the record without creating a new record, all you need to do is close the window as your original window should already be on the right record.

                         To include a new record in the existing found set and to make it the current record, I thought of a better approach as this will work with All records or any found set you might have set up:

                         Enter find mode.

                         Use your variable to specify the ID number of the original record (and yes, you will need to commit the record to capture the ID number given that it is set up with OnCommit), but use Extend Found Set to add it to the existing found set.

                         This doesn't make the new record the current record, however, so your last step is to use go to record last to go to the newly added record.

                         If you decide to use the same script for both edited and new records, you may need to use a loop to loop through your records after the extend found set action, stopping when you find the right record.