7 Replies Latest reply on Mar 11, 2017 8:35 AM by BruceRobertson

    How to perform a "find" of the current or "active" record in a script?

    _grantfk

      Hello! This is my first post on this forum. While I'm not new to FM I have limited experience with writing scripts, and am now beginning the learning curve that will, hopefully, lead to better and more complex scripts to automate our more mundane tasks.

       

      I hate to start my association with this forum off with such a seemingly simple question, but here goes...

       

      I’m trying to keep from having a script run on a found set of more than one record. I can’t trust that the users will perform a find of a unique field before they enter data into a field that will trigger the script.

       

      I'm sure I'm overthinking it, but I can’t figure out how to write a script step that performs a find of the current or "active" record as a first step? I would also like to restore the previous lookup on the last step to finish things up.

       

      Any help is greatly appreciated.

      Cheers!

        • 1. Re: How to perform a "find" of the current or "active" record in a script?
          philmodjunk

          I’m trying to keep from having a script run on a found set of more than one record.

          If [ Get ( FoundCount ) > 1 ]

           

          Peform find here

           

          End IF

          • 2. Re: How to perform a "find" of the current or "active" record in a script?
            Jason Wood

            I interpreted your question differently than philmodjunk, I was thinking you were looking for:

             

            If [ Get ( FoundCount ) = 1 ]

            Do your script here

            End If

             

            But admittedly I'm unable to comprehend most of the question. If you didn't get the answer you were expecting, try explaining the process again in more detail.

            • 3. Re: How to perform a "find" of the current or "active" record in a script?
              BruceRobertson

              I'm not sure you have to do anything at all.

              It would be helpful to see what the script actually does.

              Can you post a copy? Or a copy of your file?

              How is the script triggered? The user clicks a button?

              If the button is on the record involved, even if there multiple records in the found set, it will only operate on the current record. Unless you are doing things in your script that could involve multiple records.

              If your script is designed, for instance, to delete a record; then the script should NOT have a "Delete All Records" statement in it.

               

              For some things, like printing, you can have it print only the current record.

              Though perhaps, in that case, I can see why you might want to isolate the record.

              • 4. Re: How to perform a "find" of the current or "active" record in a script?
                _grantfk

                Bruce, quarfie and philmodjunk, I'll try to explain better.

                 

                I'm triggering the script "OnObjectExit" of either the Order Acknowledgment Number field or the Order Invoice Number field, depending on the Manufacturer. (Each pays on a different number). What's happening is it's taking the variable and, if the criteria is met, concatenating with the designated field in ALL records in the found set, not just the one I'm looking at in browse mode.

                 

                Here's the snippet I'm testing;

                 

                #------ Set the variable as the ACK # in the current record.

                Set Variable [$ack; Value: Order::Acknowledgment_Number]

                 

                #------- Determine if the current MFG uses the ACK # for payment, and if so concatenate with the MFG acronym in MZA_Order_ID

                If [Order::MFG = "art "]

                     Replace Field Contents [With dialog:Off; Order::MZA_Order_ID;

                     Replace ( Order::MZA_Order_ID; 5; 10; $ack)]

                 

                Else If [Order::MFG = "AO "]

                     Replace Field Contents [With dialog:Off; Order::MZA_Order_ID;

                     Replace ( Order::MZA_Order_ID; 4; 10; $ack)]

                End If

                 

                I will run a similar script on the Invoice Number field to determine if the MFG wants the Invoice number concatenated instead of the ACK #.

                 

                I'd be happy to provide more info or the file if necessary.

                 

                Thanks for your help!!!

                • 5. Re: How to perform a "find" of the current or "active" record in a script?
                  BruceRobertson

                  As always; the script is doing what you told it to do.

                   

                  The script step "Replace" and the calculation function "Replace" are two VERY different things.

                  Well that was obvious wasn't it!

                  Not.

                  I can certainly see how easy it would be to confuse them.

                   

                  You will want to learn about the Set Field script step.

                  It works on the current record.
                  Replace Field Contents DOES work on the found set.

                  Sometimes that is what you want. Not this time.

                   

                  If [Order::MFG = "art "]

                       Set Field[ Order::MZA_Order_ID;

                       Replace ( Order::MZA_Order_ID; 5; 10; $ack)]

                   

                  Else If [Order::MFG = "AO "]

                       Set Field[ Order::MZA_Order_ID;

                       Replace ( Order::MZA_Order_ID; 4; 10; $ack)]

                  End If

                   

                  That's a start. But there is more to say about this.

                  The fact that you are "hard wiring" the position to put the new chunk of data is certainly worrisome. What if you already did this once?

                  Work with a backup as you try this out.

                  It would certainly help if we can look at a copy of your file. Though of course you would not want to post a file with sensitive or private data. You might want to post a clone. Or a copy that has dummy data in it.

                  • 6. Re: How to perform a "find" of the current or "active" record in a script?
                    _grantfk

                    Yup... Set Field works nicely and Replace was causing me to think that a fired script would always run on every record in a found set, hence my original question. Feeling pretty foolish about now. With the Set Field step I'm able to remove the variable from the script and just combine the two fields without "hard wiring" a position

                     

                    If [Order::MFG = "art "]

                         Set Field[ Order::MZA_Order_ID; "ART " & Order::Acknowledgment Number]

                     

                    Else If [Order::MFG = "AO "]

                         Set Field[ Order::MZA_Order_ID; "AO " & Order::Acknowledgment Number'

                    End If

                     

                    Helps if you ask the right question doesn't it?

                     

                    BTW, I'm removing sensitive data from the work file so I can post it if need be in future questions.

                     

                    Thanks to all for the help!

                    • 7. Re: How to perform a "find" of the current or "active" record in a script?
                      BruceRobertson

                      Glad to help. Yes, presenting the right question and presenting enough detail is important for getting effective and timely answers.

                       

                      When formulating your question, you might also want to be aware of "the XY problem."

                       

                      http://xyproblem.info/

                      2 of 2 people found this helpful