1 2 Previous Next 16 Replies Latest reply on Jul 21, 2016 3:06 AM by mz5005

    Scripting problem

    mz5005

      I have a scripting problem of which I hink the solution will be very simple,

      but I just don't see it.

      There are 2 tables, A and B.

      Script X checks per  records from table A in table B if the record exists.

      If so, it will trigger script Y to overwrite some data of that record  (SET FIELDs).

      So far so good - all data updated correctly.

       

       

      However, when the record from table A does not exist in B, then it adds a new record

      in B and after triggers again script Y. What happens is that a new record is added successfully but no data is filled.

      I have the idea it might have got to do with the record pointer, so tried to add GO TO RELATED

      RECORD and also GO TO RECORD <last>, but it doesn't change anything.

      Screen shots of script X and Y attached (script X only look at "status 3").

      Any help greatly appreciated... wasted almost a day on this already.

        • 1. Re: Scripting problem
          beverly

          reminder: it's DevCon week, so you may not get many replies.

           

          your use of "A" and "B" don't help much. your screen shots show the name of the tables "All Contacts" and "TempImport". can you re-ask you last paragraph using the real table names?

          thank you!

          beverly

          • 2. Re: Scripting problem
            mz5005

            hi beverly,

             

            here you have the proper names filled in - hope it is clear now if not let me know.

             

            I have a scripting problem of which I think the solution will be very simple,

            but I just don't see it.

            There are 2 tables, TEMPINFO and ALLCONTACTS

            Script X checks per  records from table TEMPINFO in table ALLCONTACTS if the record exists.

            If so, it will trigger script Y to overwrite some data of that record  (SET FIELDs).

            So far so good - all data updated correctly.

             

             

            However, when the record from table TEMPINFO does not exist in ALLCONTACTS, then it adds a new record in ALLCONTACTS and after triggers again script Y. What happens is that a new record is added successfully but no data is filled.

            I have the idea it might have got to do with the record pointer, so tried to add GO TO RELATED

            RECORD and also GO TO RECORD <last>, but it doesn't change anything.

            Screen shots of script X and Y attached (script X only look at "status 3").

            Any help greatly appreciated... wasted almost a day on this already.

            • 3. Re: Scripting problem
              Magnus Fransson

              Hi mz5005,

               

              The way you are setting the fields in script Y requires there to be a "functioning" relation between the two records. To achieve that you have to set a key field with proper value. That is best done in script X, right after the record has been created, before script Y is called.

               

              Set a $Variable to the key value from the inport table before switching to the contacts table. After the new record has been created, set the key field to the value of the $Variable.

               

              With best regards Magnus Fransson.

              1 of 1 people found this helpful
              • 4. Re: Scripting problem
                beverly

                yes, Magnus! As I re-read the question with the table names, this was my guess, too. Just creating the new record has no relationship. I use the variable(s) to pass between tables, too.

                 

                Adding a "commit record" after setting the foreign key, is also good advice.

                 

                Perhaps the trigger needs to be not called if the new record has no foreign key, but then called explicitly after the new record is created, the foreign key set and record committed. That way, the flow is correct and the trigger is not "mis-fired" out of order.

                 

                beverly

                1 of 1 people found this helpful
                • 5. Re: Scripting problem
                  mz5005

                  hi magnus, thanks for your reply. will try this out and let you know.

                  • 6. Re: Scripting problem
                    mz5005

                    wow beverly.. thanks you too. but i am just a good willing amateur so will try this out step by step :-)

                    • 7. Re: Scripting problem
                      mz5005

                      beverly, magnus,

                       

                      i have made they memvars for the key fields. the tables are linked on (the combination of) email+account (and that works well because updating existing records already went well.

                       

                      however, you said "After the new record has been created, set the key field to the value of the $Variable." I don't understand how to "set a key field", because I can't add any data in the empty record? i also can't find a "set key" script step.

                       

                      screenshot of latest version attached. (the same variables are defined earlier in the script already, but to keep it simple for you i have filled them again here).

                       

                      • 8. Re: Scripting problem
                        mz5005

                        2016-07-18 (7).png

                        • 9. Re: Scripting problem
                          beverly

                          if you are in a table with a Primary field (that matches a Foreign field in a related table), first push the primary field data to a variable.

                          then go to the related table

                          create the new record

                          set the field (foreign field that would match) with the variable

                          Set Field ( myFKfield ; $varMyPKfield )

                          then commit the record. There is now a "matching" record between the two tables. You can push data from the main table to the newly-related table as you are now.

                           

                          beverly

                          • 10. Re: Scripting problem
                            wimdecorte

                            You can't use "+" to concatenate two strings.  You need to use the "&" operator.

                            "+" is for mathematical operations.

                            1 of 1 people found this helpful
                            • 11. Re: Scripting problem
                              mz5005

                              ok beverly, wim.. will continue tomorrow it's quite late already here.

                              thanks for your effort.

                              • 12. Re: Scripting problem
                                Magnus Fransson

                                Hi mz5005,

                                 

                                It's not "set key".     I'm talking about a "key field" that should be set, (using "set field").

                                 

                                As you are working on two different tables you have so switch between two different contexts, by switching between two different layouts.

                                 

                                Something like:

                                ...

                                "Go to layout" for context "Import".

                                "Set variable"(s) with value(s) from "key field".

                                "go to layout" for context "contact".

                                "New record".

                                "Set field" "Key field" with value(s) of "variable"

                                "Run script" Y.

                                ...

                                 

                                 

                                With best regards Magnus Fransson.

                                1 of 1 people found this helpful
                                • 13. Re: Scripting problem
                                  mz5005

                                  thanks wim - changed already.

                                  • 14. Re: Scripting problem
                                    mz5005

                                    hi beverly, fran,

                                     

                                    i think i have done as you both explained. see screenshots. result is unfortunately still only empty records.

                                    so i also enclosed the relationship chart. the 2 key fields are both set the same as on pic.

                                     

                                    any idea what might be wrong?

                                     

                                    script X

                                    Script X status Th0721.PNG

                                     

                                    script Y (unchanged)

                                    Script Y status Th0721.PNG

                                     

                                    relationships

                                     

                                    Relationships.PNG

                                     

                                    Relationships2.PNG

                                     

                                    thanks for your time!

                                    1 2 Previous Next