14 Replies Latest reply on Aug 13, 2017 11:18 AM by user29748

    GetFieldName not working with CWP XML

    user29748

      Product and version FileMaker Server 16.0.2.212

      OS and version Windows Server 2012 R2

      Browser and version (for WebDirect only)

      Hardware VM

      Description I have a script that gets a field name with the function GetFieldName(), and it works perfectly with FMP. If I call this script with CWP with the fmsresultset.xml grammar, the script works, but GetFieldName() returns an empty string.

      This is not documented anywhere.

       

      Workaround There seems to be no workaround, I'm actually stuck.

        • 1. Re: GetFieldName not working with CWP XML
          wimdecorte

          Can you post the actual script so that we can see how constructed the script?

          1 of 1 people found this helpful
          • 2. Re: GetFieldName not working with CWP XML
            user29748

            Here's the simplest script that causes the error:

             

            Set Variable [ $name ; "{\"fieldName\": \"" & GetFieldName ( Job::client_name ) & "\"}" ]

            #...callback code, insert from URL

             

            I can get the result from the XML request because it sends it as an HTTP callback. The callback code is perfectly working in both conditions, the function doesn't.

             

            It works from FMP:

            POST /callback/fileMaker?test 200 0.589 ms - 2

            { fieldName: 'Job::client_name' }

             

            Just not from CWP:

            POST /callback/fileMaker?test 200 0.475 ms - 2

            { fieldName: '' }

             

            I can reproduce it 100% of the times.

            • 3. Re: GetFieldName not working with CWP XML
              wimdecorte

              You lost me on the call-back code.  What does that look like?

               

              So you are running a script through the XML API and that scripts calls back to what?

              • 4. Re: GetFieldName not working with CWP XML
                wimdecorte

                Here's my test:

                 

                Script:

                 

                script 2017-08-10_09-06-55.png

                 

                Record:

                 

                record 2017-08-10_09-07-13.png

                 

                And the XML API call that runs the script before returning a 'find all". As you can see the result of the GetFieldName function call is there.

                 

                postman 2017-08-10_09-07-47.png

                • 5. Re: GetFieldName not working with CWP XML
                  user29748

                  I use an intermediate server to handle script responses. Actually.. using a field is a nice idea indeed! I didn't think about that, I just read in the manual that script results are not supported in the XML API and so I created a callback server... I'll replicate the solution.

                   

                  ...it doesn't work on global fields...

                  ...no, it does, but I have to create a blank record. Ok.

                   

                  ...and still it doesn't show the field name.

                   

                  This is very strange, and if your setup works it only means it has to do with my instance or something. I'll do some tests and I'll write back here the results.

                  • 6. Re: GetFieldName not working with CWP XML
                    user29748

                    NO! I GOT IT! It happens when I reference a table from another file. The two files are hosted on the same FileMaker Server.

                    If I use a local table it works, but if I give it an instance of a table in another file it doesn't.

                    1 of 1 people found this helpful
                    • 7. Re: GetFieldName not working with CWP XML
                      user29748

                      I can add that even calling scripts from other files doesn't work. When I get the results I get an empty text, while executing the same script locally works.

                       

                      So, if I have a script in a file called BRIDGE, and I call a script with CWP/XML, and that script calls another script in a file DATA, then when I call Get ( ScriptResult ) after it, it returns nothing. Even if I explicitly tell it to return some text.

                       

                      This is by far the worst API I've ever worked with. Why isn't it possible to build some encapsulation? What I'm aiming is to have an access layer for my data using a façade of scripts. This seems impossible to implement, given the current limitations.

                      • 8. Re: GetFieldName not working with CWP XML
                        wimdecorte

                        You can use the encapsulation that you are after.  See screenshots.  I have a TO for "cake' on my graph, and as you can tell by its name being in italics it is from a different file.

                         

                        2017-08-10_11-42-09.png

                         

                        If I amend the script to use GetFieldName for a field from that remote file:

                         

                        2017-08-10_11-48-38.png

                         

                         

                        and then make an XML API call as before, I get the result for the GFN function properly:

                         

                        passthrough 2017-08-13_10-39-31.png

                         

                        Remember that it is not the privileges in the file that you make the call against (the one specified as -db= ) that are important, but the privileges in the file where the table lives.  So the account that you use in the -db file has to also exist in the data file, and the priv set for that account has to allow the XML api.

                        1 of 1 people found this helpful
                        • 9. Re: GetFieldName not working with CWP XML
                          user29748

                          Thanks for the answer.

                           

                          This is confusing then... I checked everything, the account is (temporarily) a [Full Access] with XML permissions on both files.

                           

                          The only difference... is that my layout is on the remote table. I'm setting it on a local.

                          ..that works. Brilliant!

                           

                          Setting the table to an internal one, made only of global fields...

                          ...still works. Weird, I tried that before.

                           

                          ...and now even the script from the other file returns data!! What the heck?? I think I changed something critical while following your example.

                           

                          ...queries work fine...

                           

                          Let's see if I change the user to the old one...

                          ...FAILS

                           

                          So, let's try to tell the DATA file to re-login with the full access user before performing the query (Perform Script on DATA -> Re-Login), like in the original script...

                          ...NOPE

                           

                          I recreate a user in DATA with the same exact credentials as BRIDGE (the user is called "API"), but with full access...

                          [by the way, this all worked in the FMP application, just not in XML]

                          ...WORKS

                           

                          I give that user the privileges it should have...

                          ...YEP, STILL WORKS

                           

                          After some other tests I see that the Re-Login script step is actually the culprit. It fails (and I didn't check the return code of my script).

                           

                          So, to recap:

                          It seems to be working when using the exact same credentials on all files (as it should be, actually), the Re-Login script step works fine on FMP but it fails with CWP, and that is the cause of the missing data.

                           

                          That's excellent, thanks a lot for testing this for me. My setup proved to be faulty in this specific situation, and that was the main cause of confusion.

                           

                          For other people who might have some similar issues: it has to do with security, try to do incremental testing starting from a full access account with everything enabled. Obviously the logs and error codes are completely clueless.

                           

                          p.s.: You're from Soliant?

                          • 10. Re: GetFieldName not working with CWP XML
                            wimdecorte

                            John White wrote:

                             

                             

                             

                            p.s.: You're from Soliant?

                             

                            Yes.

                            • 11. Re: GetFieldName not working with CWP XML
                              wimdecorte

                              John White wrote:

                               

                               

                              After some other tests I see that the Re-Login script step is actually the culprit. It fails (and I didn't check the return code of my script).

                               

                              The re-login script wouldn't help in this case because it only acts on the file that the script is in, it will not re-login in all open files.

                              • 12. Re: GetFieldName not working with CWP XML
                                user29748

                                It does, since I call a script on the remote file, and THAT script has the re-login step. It's a crucial part of my security model, since i use Google OAuth without the poor native filemaker implementation. Every file has an internal account bound to a privilege set, and the central database holds the encrypted credentials. The login script securely checks the google login and returned token, then decrypts the credentials and tells all files to re-login with the correct internal account.

                                 

                                Sounds like a hassle? Think about when I have to change these passwords for all files. There's a script that automates that too. This is the only solution I could invent for handling native FM security groups with external authentication systems.

                                 

                                By the way, thanks for the amazing guides (the Soliant website), you guys have the best FM stuff I've seen.

                                • 13. Re: GetFieldName not working with CWP XML
                                  beverly

                                  Wim is with Soliant now. But really he's from the world.

                                   

                                  Sent from miPhone

                                  • 14. Re: GetFieldName not working with CWP XML
                                    user29748

                                    I guess that would correct my awkward english