4 Replies Latest reply on Nov 1, 2016 9:04 PM by dig

    Adding new related record in portal script...

    alinicjones

      I can't quite figure out what i'm missing in these script steps to get the portal to go to the next record. instead it updates the record that was previously created. See script steps below.

       

      Tables:

      Student

      Rotation

       

      The portal is based off of the Student_Rotation relationship.

       

      The Rotation portal is located on the Student layout. i have a button that opens a popover where a period is slected and then the service. OnObjectEnter is on the portal, it is set to perform the "Add New Rotation" script. The purpose is to Create a new record set the current records Student ID number.

       

      Add New Rotation

      Set Error Capture [On]

      Allow User Abort [Off]

      #

      Set Variable [ $StudentID; Value: Student::__kp_StudentID

      #

      New Window [Name: "New Rotation"; Top:10000; Left: 10000; Style: Document ]

      Go to Layout ["dev_rotation" (Rotation) ]

      New Record/Request

      Set Field [Rotation::_kf_StudentID; $StudentID ]

      Commit Records/Request [ No dialog]

      Close Window [Current Window]

      Refresh Window [Flush cached join results]

      #

      If [Get (ActiveLayoutObjectName ) = "Button | Select Period"

      Perform Script [ "Popover | Add New Rotation_Period" ]

      Else If [ Get ( ActiveLaoyoutObjectName ) = "Button | Select Service" ]

      Perform Script [ "Popover | Add New Rotation_Service" ]

      End If

       

      on this popover i have a button where they select the appropriate period for the rotation.

      Add Period.png

      The script for this button is:

       

      Popover | Add New Roation_Period

      Set Error Capture [On]

      Allow User Abort [Off]

      #

      If [not IsEmpty ( Get (ScriptParameter ) ) ]

      Set Variable [ $SELECTED_Period; Value: Get ( ScriptParameter ) ]

      End If

      Go to Field [ student_ROTATION::PeriodName ]

      Go to Portal Row [ Select; First ]

      Set Field [ student_ROTATION::_kf_PeriodID; GetValue ( $SELECTED_Period; 1 ) ]

      Set Field [ student_ROTATION::PeriodName; GetValue ( $SELECTED_Period; 2 ) ]

      #

      Set Script Animation [On]

      Go to Object [ Object Name: "Select Service"

       

      There is a slide control in the popover. Once the period is selected it 'slides' to the service selection area of the popover.

      Add Service.png

      in this section there is another button that triggers the script

       

      Popover | Add New Rotation_Service

      Set Error Capture [On]

      Allow User Abort [Off]

      #

      If [not IsEmpty ( Get (ScriptParameter ) ) ]

      Set Variable [ $SELECTED_Service; Value: Get ( ScriptParameter ) ]

      End If

      Go to Field [ student_ROTATION::ServiceName ]

      Go to Portal Row [ Select; Previous]

      Set Field [ student_ROTATION::ServiceName; GetValue ( $SELECTED_Service; 1 ) ]

      Set Field [ student_ROTATION::_kf_ServiceID; GetValue ( $SELECTED_Service; 2 ) ]

      #

      Commit Records/Request [No dialog]

      Set Script Animation [On]

      Got to Object [Object Name: "Select Period" ]

      Close Popover

      #

      Refresh Window [Flush cashed join results]

       

      Student Rotation.png

      The first records works fine but when i try to add a new rotation it updates the record that was just created. I'm sure i have something out of order or i'm missing a script set or something. I have tried a number of different thing but i can't seem to get it to work right. Any help would be wonderful!!

      Thank you in advance!

        • 1. Re: Adding new related record in portal script...
          erolst

          I think you could create this workflow in a much less convoluted way – e.g. let the user select period and service first, capture that in two $$vars, and only then create the related record using that selection, sans portal. This would also allow you to add a Cancel button – never script a (selection) dialog without it! .

           

          Until then, the problem seems to be that you're landing on the wrong portal row (obviously); not the least because Go to Portal Row [ previous ] has no meaning once you've left a portal. If your portal is unsorted (except, of course, for creation order), the simplest way would be to

           

          Go to Object | objectNameOfPortal ]

          Go to Portal Row [ last ]

           

          If the portal is sorted, then to find the correct row, you could e.g. store the primary ID of the new rotation record, then either calculate the correct portal row (its index position in a list of all related primary IDs will be the portal row number – provided the portal isn't sorted differently from the relationship, and/or filtered), or loop through the portal until you find the record with that key; or, if you have a creation timestamp, read the latest timestamp of all related records and loop until you find the record with that datum.

          • 2. Re: Adding new related record in portal script...
            BruceHerbach

            Hi,

             

            Attached is a simple setup that I think does what you want.  I added source tables for Periods and services so that they can be selected in portals in a Popover. 

             

            It creates the Rotation record using a setup I picked up from another developer,  Kevin Frank.  For this I added a TO based on the rotations table that is attached to a Global field in the Student table.  Student::NEWRECORD_ID = New_Rotation::ID  and set the Allow creation of records in this table via this relationship, check box. 

             

            In the Popover are two portals,  Period and Service.  The fields are set as buttons.  Click one sets the value into a global variable.  So you select what you want,  then click the Create Rotation button.

             

            If you want you can create value lists from the Periods and Services tables and add these as menus in the Rotations portal on the student record.

             

            Hope you find this helpful.

            1 of 1 people found this helpful
            • 3. Re: Adding new related record in portal script...
              alinicjones

              Thank you so much!! That was much more simple!

              • 4. Re: Adding new related record in portal script...
                dig

                This solution still has value, thank you.