12 Replies Latest reply on Jan 17, 2017 8:18 AM by glennatenr

    Usage of constrain found set in a script

    glennatenr

      Hi,

       

      I am having a problem with an automated script.  We want the user to be able to create a found set of records

      but only records that are of their sales.  The user is constrained to only their records on entering the application

      and that works fine.

       

      If I is use a button (say #1) with the script:    Enter Find Mode [Pause:Off]    The user is able to make their selection but other users records

      appear as well in the search result.

       

      If I have another scripted button (say #2) with the script :

       

      IF [Get ( AccountPrivilegeSetName)= "user"]

            Constrain Found Set  [Restore]                        *  (where the constraint is on their login name)

      End IF

       

      The action from button (#2) properly constrains the result from (#1) and displays the proper data.   If we place all of the script in one place  with both commands it fails to execute.  I assume that since the end result works that the scripting is correct, but even trying to call script #2 from button #1 fails to work.

       

      If the script executes correctly separately by hitting 2 different buttons,  why wouldn't it work in one script.

       

      Any Ideas ?

       

      Thanks


      Glenn

        • 1. Re: Usage of constrain found set in a script
          BruceRobertson

          You say you have written a combined script; and it doesn't work; but you have not shown us that script.

          • 2. Re: Usage of constrain found set in a script
            glennatenr

            Thanks Bruce,

             

            the original script was

             

            Enter Find Mode [Pause:Off]  

             

            IF [Get ( AccountPrivilegeSetName)= "user"]

                  Constrain Found Set  [Restore]                      

            End IF

             

            I tried pause on as well, as I mentioned they work as desired separately, I didn't see why they would not work

            if they were combined.

             

            Glenn

            • 3. Re: Usage of constrain found set in a script
              BruceRobertson

              I suggest:

              Enter Find Mode [Pause]  

              Perform Find [ ]

              IF [Get ( AccountPrivilegeSetName)= "user"]

                    Constrain Found Set  [Restore]                      

              End IF

              • 4. Re: Usage of constrain found set in a script
                BruceRobertson

                Note that this is really NOT the way to robustly handle access privileges.

                You should be using privilege sets to accomplish this.

                When properly set up, any find operation automatically restricts the record set.

                 

                And have I mentioned often enough, today, how much I find Perform Find [ restore ] to be a really terrible method?

                It does work.

                But it creates unreadable scripts and incompetent unskilled scripters.

                 

                Learn to write explicit Find scripts.

                 

                Enter Find Mode [ ]

                Set Field [ ..... ]

                Perform Find [ ]

                • 5. Re: Usage of constrain found set in a script
                  philmodjunk

                  You can also set up the OnModeChange to run a script that constrains the found set every time the user enters Browse mode. This will automatically constrain after any manual find.

                   

                  But I recommend that you use Manage |Security to limit which records can be accessed by a given user. All finds--whether scripted or manual will then automatically constrain without any need to script it.

                  • 6. Re: Usage of constrain found set in a script
                    glennatenr

                    Phil,

                     

                    I'm lost,  as I said I can execute the functions separately

                     

                    Enter Find Mode [Pause:Off]  

                     

                    IF [Get ( AccountPrivilegeSetName)= "user"]

                          Constrain Found Set  [Restore]                      

                    End IF

                     

                    If I place the following in the script

                     

                    Enter Find Mode [Pause:Off]

                    Constrain Found Set  [Restore]

                     

                    which again, work separately,  and watch it execute through the debugger it seems to blow

                    straight through find mode request as if it were not even there

                     

                    I searched through the online documentation but I have no idea how to or even where to look

                    to handle this through security, being able to constrain through a global security function would

                    make this a lot easier - can you help me out ?

                     

                    Thanks

                     

                    Glenn

                    • 7. Re: Usage of constrain found set in a script
                      ninja

                      Simplify it (make it more readable) by pulling the find criteria out in the open...

                       

                      IF [Get ( AccountPrivilegeSetName)= "user"]

                          Enter Find Mode

                          SetField ( AccountName ; Get(AccountName)  )

                          Constrain Found set []

                          Perform find []

                      End IF

                       

                      I assume, of course, that you are already in a found set to start with.

                      If you are not already in a found set, the "Constrain Found Set" doesn't do anything and you're just performing a find.

                      • 8. Re: Usage of constrain found set in a script
                        BruceRobertson

                        What is Peform Find doing in there if you're trying to constrain?

                         

                        IF [Get ( AccountPrivilegeSetName)= "user"]

                            Enter Find Mode

                            SetField ( AccountName ; Get(AccountName)  )

                            Constrain Found set []

                        End IF

                        • 9. Re: Usage of constrain found set in a script
                          BruceRobertson

                          Did you not look at my example?

                          Do not turn pause off.

                           

                          Enter Find Mode [Pause]  

                          #user enters their stuff and continues thus

                          #triggering the find; within the script

                          Perform Find [ ]

                          IF [Get ( AccountPrivilegeSetName)= "user"]

                                Constrain Found Set  [Restore]                      

                          End IF

                           

                           

                          • 10. Re: Usage of constrain found set in a script
                            glennatenr

                            Bruce I did try it both ways and it was not functioning.  I think the problem was in the

                            buried constrain request, my error , not being able to see what's lurking behind the

                            restore seems to be the problem because once I simplified it it worked.

                             

                            I used Eric's method and broke it out, I modified it because I realize I don't need the

                            if statement in this instance the users on this screen are all users not admin or design

                            but I don't think that the if was an issue as it stepped into it just fine

                             

                            I used the following and it worked perfectly

                             

                            Enter Find Mode [Pause:On]

                            Set Field [Quote Log::Sales Rep; $$accountname ]

                            Constrain Found Set [ ]

                            Perform Find [ ]

                             

                            Your guys are truly amazing for helping me through this I really appreciate all of the help !

                             

                            Glenn

                            • 11. Re: Usage of constrain found set in a script
                              glennatenr

                              Thanks Eric for that Tip - breaking it out really helped !

                              • 12. Re: Usage of constrain found set in a script
                                BruceRobertson

                                Actually, Eric's method doesn't work.

                                Once you execute the Constrain, the Perform Find never happens.

                                It would be easy to prove with an example file. Let's say you're searching for either of two values in the Category field.

                                A; or B. Valid records exist for both.

                                You do the Eric-constrain when searching for A.

                                Now your found set is Category A; User.

                                 

                                Try to do the Eric method to get to the B records.

                                You can't.