6 Replies Latest reply on Aug 8, 2017 10:09 AM by jackrodgersjr

    How to get a script to function on found set

    xxx202xxx

      Scenario:

      I am attempting to run a script where I am looking for [ServicMGMT::Status >= (Get (CurrentTimestamp) -7*24*3600)].

       

      Problem:

      I have this script that is ran on the server side that queries the database.  My problem is that it only acts on the first record of the found set.  I will need it to evaluate all the records in the found set which is rouglhly 15 to 20 records.

       

      go to layout

      enter find mode

      set field [ServicMGMT::Status; "Pending"]

      perform find

      sort records [Ascending; ServiceMGMT::ModifiedTime]

      Go to Record/Request/Page [First]

      If [ServiceMGMT::ModifiedTime >= (Get (CurrentTimestamp -7 * 24 * 3600)]

           Send Mail to AccountName

      End if

      show all records

      exit script

        • 1. Re: How to get a script to function on found set
          coherentkris

          go to layout

          enter find mode

          set field [ServicMGMT::Status; "Pending"]

          perform find

          sort records [Ascending; ServiceMGMT::ModifiedTime]

          // sort records may throw error if attempted on null found set

          Go to Record/Request/Page [First]

          // GtR/R/P may throw error if attempted on null found set

          loop

          exit loop if Get(FoundCount) = 0

          If [ServiceMGMT::ModifiedTime >= (Get (CurrentTimestamp -7 * 24 * 3600)]

               Send Mail to AccountName

          End if

          go to next, end at last

          end loop

          show all records

          exit script

          • 2. Re: How to get a script to function on found set
            jackrodgersjr

            go to layout

            enter find mode

            set field [ServicMGMT::Status; "Pending"]

            perform find

             

            if get(lasterror) = 0 

             

                sort records [Ascending; ServiceMGMT::ModifiedTime]

                Go to Record/Request/Page [First]

                If [ServiceMGMT::ModifiedTime >= (Get (CurrentTimestamp -7 * 24 * 3600)]

                    Send Mail to AccountName

                End if

             

            else

             

            you can show a custom dialog describing error, etc.

             

            end if

             

            show all records

            exit script

            • 3. Re: How to get a script to function on found set
              coherentkris

              jackrodgersjr

              Your suggestion will not solve the OP's problem as it will only operate on the first found record. If you don't insert a loop in there somewhere it will not meet the requirements.

              it also introduces a problem because the Op specified Run on server and your suggested else clause involves a dialog to echo an error condition and custom dialogs do not work on server. The right way to see error conditions when run on server is to pass them out of the script at Exit Script.

               

              The best option is to ...

              go to layout

              enter find mode

              set field [ServicMGMT::Status; "Pending"]

              perform find

              set variable $err = Get ( Last Error ) or Get ( Found Count )

              If $err not equal to 401 or 0 // depending on what is stored in the var

                   sort records [Ascending; ServiceMGMT::ModifiedTime]

                   Go to Record/Request/Page [First]

                   loop

                        If [ServiceMGMT::ModifiedTime >= (Get (CurrentTimestamp -7 * 24 * 3600)]

                             Send Mail to AccountName

                        End if

                        go to next, end at last

                   end loop

              end if

              show all records

              // show all records is not needed when run on server because the session and its context is lost once the script terminates

              exit script ( return $err )

              1 of 1 people found this helpful
              • 4. Re: How to get a script to function on found set
                philmodjunk

                Why not reduce the found set to just those records that match the specified criteria for both status and modified time?

                 

                Set Error Capture [on]

                enter find mode

                set field [ServicMGMT::Status; "Pending"]

                Set field [ServiceMGMT::ModifiedTime ; ">=" & (Get (CurrentTimestamp -7 * 24 * 3600)]

                perform find

                If [ Get ( FOundCount ) > 0 ]

                   #At this point, you now have a found set of only the records matching the specified criteria, no need to check modified time in each record in a loop. No need to sort the records either.

                    loop

                           Send Mail to AccountName

                          go to next, end at last

                     end loop

                End If

                 

                Depending on the options you select in Send Mail and how you access the needed email addresses, you might not need the loop

                • 6. Re: How to get a script to function on found set
                  jackrodgersjr

                  coherentkris wrote:

                   

                  jackrodgersjr

                  Your suggestion will not solve the OP's problem as it will only operate on the first found record. If you don't insert a loop in there somewhere it will not meet the requirements.

                  YOu are correct. Someone deleted my Loop/exit if/endloop lines. I think I have malware on my computer...