8 Replies Latest reply on Nov 18, 2015 1:03 PM by jayGamel

    Set field problems

    jayGamel

      Here's the setup (the files are appropriately related):

      file:CUSTOMERS - !@ !New Note script

      Set Variable[$cid; Value:Customers::CID]

      Perform Script [“newnote” from file: “Notes”]

       

      file:NOTES - newnote script

      Go to Layout [“New note (Notes)]

      New Record/Request

      Set Field [Notes::CID; Notes::CID=$cid]    {result is a number - both fields are numbers]

      Go to Field [Notes::Note]

      Adjust Window [Resize to Fit]

      The problem is the new note has the CID of “1” instead of the correct value, such as “1213”. For some reason the local variable $cid is not setting to the value of the record I’m looking at when I run the CUSTOMER script Newnote, that would “1213”. Instead, it is “1”.

      What’s happening? I have trouble using the “set field” in a lot of instances. Copy and paste works fine, but leaves the memory loaded with the CID which is aggravating the next time I paste something. And every Filemaker tutorial says use the “set field” over “copy and paste.”

      Any help will be appreciated.file

       

      running ElCapitan; mac 7,1; 6 gigs; FMPA 11

        • 1. Re: Set field problems
          BruceRobertson

          Time to learn about using script parameters. When one script calls another, there is an OPTION to send a script parameter.

          When a script runs, there is an option for you to read this parameter, and then define a variable within the called script, or otherwise take action depending on the content of the parameter.

           

          Calll script using paramter.pngscript reads script param.png

          • 2. Re: Set field problems
            keywords

            Just to expand a little on Bruce's post, you set the script parameter in the Perform Script step in the calling script, as shown in Bruce's screenshot, so the step in your script will look like this—

            "Perform Script [ newnote” from file: “Notes”; Parameter: $cid ]"

            Then you add the following first step in the called script—

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

            Thus the $cid variable gets passed to the new script.


            Remember that local variables—the ones with a single $—are sometimes called script variables because they persist only within the script which creates them. The above is the method passes them to a called script, effectively creating them anew within that script.

            • 3. Re: Set field problems
              BruceRobertson

              And to expand just a bit further, altogether there are four basic parts to the inter-script communication process.

              When calling another script you can send a script parameter.

              The called script can use get( scriptParameter ) to see if any information was sent.

               

              At the end of the called script you can create a result and send that result back, using the Exit Script [ result ] script step.

              It is common to send back, for instance, the ID of the newly created record; or an error number and error information if the called script failed.

               

              The originating script captures this information with get( scriptResult )

               

              I send you a request.

              Please bake a cake.

              When sending the request, I write "chocolate" on a post it note and give it to you.

              You receive the request. You see I asked for a cake.

              You see I included a post it note; you read it.

              You look in the cupboard. You have no chocolate.

              You write "sorry we're out of chocolate" on a post it note.

              You send the note back to me.

              I look at the note.

              I call a different bakery.

              • 4. Re: Set field problems
                jayGamel

                I must be denser than usual this morning, but after setting the customer

                script to

                set variable $cid= customer:CID

                and open foreign script, option send parameter "$cid" --

                (although why this couldn't just be "customer:CID" is beyond me.

                 

                and setting the notes file script to

                set variable (name=$cid; variable=$cid{which should be the passed

                parameter}), nothing is pasted in the new notes record CID field.

                 

                and I don't see any of this passed parameter stuff in set field help stuff.

                 

                why cant the notes CID field be set to equal the info in the customer

                field? i.e., set field notes cid=customer cid? and skip the variable and

                passing parameters.

                 

                BTW: these are separate files, holdover from an old DB, but are related

                properly. I think.

                 

                what's the point of relating fields and having a set field action if you

                have to code a separate pair of transactions to pass a value between the

                two records?

                 

                Thank you for your help. I do appreciate it, but I'm really confused about

                this. When I tried setting up a Get ($cid), FMPA said that wasn't possible.

                Didn't work with Get(CUSTOMER::$cid, or CUSTOMER::CID, either.

                 

                On Tue, Nov 17, 2015 at 4:21 PM, BruceRobertson <noreply@filemaker.com>

                • 5. Re: Set field problems
                  BruceRobertson

                  Try following the instructions exactly as written.

                  There is no such function as get($cid)

                  • 6. Re: Set field problems
                    BruceRobertson

                    The called script knows nothing about any variables you have declared in the calling script.

                    If you have sent a parameter, you get whatever was sent with get( scriptParameter)

                    • 7. Re: Set field problems
                      BruceRobertson

                      FIle 2 knows nothing about what is happening in file 1. That is why you need to send parameters; and why you must do other things in the called script to control context, such as go to layout. The context in file 2 might be a Products layout; or a Sales layout; or a Note record for another Contact.

                      • 8. Re: Set field problems
                        jayGamel

                        Et voilà, it works. Thank you very much and I'll keep working on

                        understanding this.

                         

                        On Wed, Nov 18, 2015 at 11:50 AM, BruceRobertson <noreply@filemaker.com>