1 Reply Latest reply on Jun 18, 2012 8:15 AM by GuyStevens

    How can I loop through a certain foreign key filed in a list view?

    ScottMcpherson

      Title

      How can I loop through a certain foreign key filed in a list view?

      Post

      Hello, I have a list view of case notes and at the top of that view I have a button to add a new note. When the button is pressed it jumps to the bottom of the list view, the script sets the foreign key for the new note to be added, and the script then goes to the note field so that the user can then begin typing in the new note. The problem I'm having with this approach is that if the user clicks the show all button and then clicks the add new note button, there are several foreign keys in the list view and my script can not accurately set the foreign key to the new note. The way I'm trying to correct that is if the user clicks the add note button the script will:

      1. set a variable called $CaseName to the first foreign key in the list view
      2. set a vaiable $CaseFkCount equal to the total count of all of the foreign keys in the list view
      3. set $Counter variable equal to 1
      4. loop through each record in the list view and if a foreign key does not equal the $CaseName variable then pop up a custom dialog box telling the user that they must be in the context of only one case
      5. each time the loop is iterated, 1 is added to $Counter
      6. if the loop finishes without step 4 equaling true then proceed to set the foreing key for the new note and go to the note field

      How Can I make this work?

      fmcode.png

        • 1. Re: How can I loop through a certain foreign key filed in a list view?
          GuyStevens

          The question is how do you get to that list view? If you start from a record that holds the Foreign Key you need I would suggest setting that foreign key either ina persistent variable "$$ForeignKey" Or I would set it in a global field in the table the list view is based on.

          You would do this just before going to the list layout.

          Then anyone can do whatever they want in that list and when they create a new note you can still take the Foreign Key from the global field.

          Also is it maybe possible to display the notes in a portal? Then you can create a "New Note" button on the record that actually contains the foreign key.

          Or you could just create a new note in the portal and you wouldn't even have to worry about setting the FK.