3 Replies Latest reply on Apr 11, 2013 11:42 AM by Stephen Huston

    How to prevent leaving the record if the portal record did not meet certain requirement

    jameshoty

      A Stock table is 1-to-many related to Stock Material table (typical relationship setup).

      Screen Shot 2013-04-10 at 10.25.59PM.png

       

      The purpose of Stock_Material_Total_Weight TO is so that I can display the total weight of all the material for a Stock item

      Screen Shot 2013-04-10 at 10.29.30PM.png

       

      The requirement is that the total weight of all the material for the same stock must be exactly 100. The user can freely modify any material BUT can not leave this master record (either by going to the next previous record, jumping to another layout etc) if the total wieght is not 100.

       

      I have a script to detect the total weight and have trial and error various ways but not successful. I tried layout setup, portal setup, also script trigger for the field etc.

       

      Thanks

        • 1. Re: How to prevent leaving the record if the portal record did not meet certain requirement
          DavidJondreau

          I think you've got it backwards.

           

          Assuming Stock Material can be used in different Stock Items, you should have Stock Material Total Weight ( which is really a Stock Material Join table ) be between Stock and Material. You need to add records to this Join table to build up a record in Stock. Then have a calc field in Stock Sum() on the Weight of Stock Material Join.

           

          Once you've got the weight calculating correctly, you've got to get the user behavior down. That could easily be done with an OnObjectExit script trigger on the Portal.

          • 2. Re: How to prevent leaving the record if the portal record did not meet certain requirement
            jameshoty

            Thanks for your advice. I reworked and remove the TO "Stock Material Total Weight" & the Total Weight field in Stock Material table. Instead I created a simialr calculation field in Stock table to sum the Weight field in Stock Material table as recommended by you. Learn something new ;-)

             

            Screen Shot 2013-04-11 at 4.03.20PM.png

             

              Screen Shot 2013-04-11 at 4.05.51PM.png

             

            At this junction, no script trigger is being applied to the Weight field (of Stock Material) as well as the portal. The user can freely modify the weight field and the total weight at the bottom of the portal will get changed everytime the weight of the individual material is being modified. This is good as the user get to know the updated total as she starts modifying.

            Screen Shot 2013-04-11 at 3.25.34PM.png

             

            I created a simple script to check if the total of the weight for all the sub material is equal to 100 and Set Script Trigger to the Portal (onobjectexit)

             

            Screen Shot 2013-04-11 at 4.11.22PM.pngScreen Shot 2013-04-11 at 4.13.46PM.png

             

            I tested it and it works BUT unfortuanately, after closing the message prompt, I am still able to go to other record or another layout (eg. via a button). Is there a way to "Prevent Totally" from ignoring this constraint and that the user must resolve the total weight to 100 before she can move to other screen? I set script trigger at the layout setup (onlayoutexit) to this same script and doesn't help, meaning I can still exit to other layout.

             

            I learn and I appreciate. Thanks.

            • 3. Re: How to prevent leaving the record if the portal record did not meet certain requirement
              Stephen Huston

              You could have this operation run from a separate/new Modal window which the user cannot exit until your specific criteria are met.

               

              Keep in mind if you do this, by whatever means, you must provide some sort of roll-back to cancel the entire operation if your user realizes they can't complete the operation at that time -- otherwise they will probably force-quit the application!