1 2 Previous Next 16 Replies Latest reply on Feb 21, 2017 6:16 AM by beverly

    CWP with XML: executing a script

    planteg

      Hello,

       

      I am writing a program that will interface with a file on FMS using XML. Things are going pretty well, except that I would like to execute a script and get the returned value. When I try, I get the first record from the table linked to the layout instead of the script result.

       

      As far as I understand from the Custom Web Publishing Guide, you can't just call a script, you need to do some thing else prior of after execution the script:

      xmlscript.jpg

       

      Is that correct ? Second question: I program in Python and use a Python wrapper that generates a URL. The generated URL is:

       

      http://somesite.com:8080/fmi/xml/fmresultset.xml?- db=Ballots&-lay=listeeti&-script=traiterCodeABarre&-script.param=OP____23&-findall=

       

      The URL seems incorrect: if I copy in a browser, I get error = 4, but run in my program I get the first record.

       

      What am I doing wrong ?

       

      Thanks

        • 1. Re: CWP with XML: executing a script
          wimdecorte

          What does your script do?  You can not for instance produce a found set in the script and expect that to be the data that is returned.  That is not its purpose.

           

          For that reason you typically would use the "-findany" operator when you create a URL to execute a script so that you minimize the data that gets returned.  If you do a "-findall" like in your example then you are making your program wait much longer than is needed.

          Use a layout with no fields on it and use the "-findany" operator when calling a script.

          • 2. Re: CWP with XML: executing a script
            wimdecorte

            planteg wrote:

             

            As far as I understand from the Custom Web Publishing Guide, you can't just call a script, you need to do some thing else prior of after execution the script:

             

            You need an operator but nothing else.  "-findany" will do.

            • 3. Re: CWP with XML: executing a script
              planteg

              Hi Wim,

               

              the script does noting useful:

              traiteCodeABarre.jpg

              That was only to play around to see what would get back, the Python wrapper does not send back everything it got in XML. I was surprised to get one record instead of the contents of $rep. There are about 25 records in the underlying table.

               

              I replaced -findall= by -findany, and got error = 0.

               

              I still don't get the script return value but that seems to be a matter of supplying another parameter in the Python call.

              • 4. Re: CWP with XML: executing a script
                beverly

                Try the call, but not inside Python. Just the raw XML returned to the browser. What do you get?

                 

                Sent from miPhone

                1 of 1 people found this helpful
                • 5. Re: CWP with XML: executing a script
                  wimdecorte

                  planteg wrote:

                   

                   

                  I still don't get the script return value

                   

                  I don't think you can at all.

                  1 of 1 people found this helpful
                  • 6. Re: CWP with XML: executing a script
                    user19752

                    Agreed. XML request always return record set.

                     

                    So, you can set the value to a global field, then use a result layout that have only the global field.

                    1 of 1 people found this helpful
                    • 7. Re: CWP with XML: executing a script
                      planteg

                      @beverly ,

                       

                      running right in Chrome with findall, I get all the records plus the other things like the database name, date format, etc. But not the script returned value. So wimdecorte is right.

                       

                      In Python, even though I execute the script with -findall (automatically added by the wrapper), I get only the first record, because the wrapper returns only the first record.

                       

                      Then the conclusion is:

                       

                      • with XML you will not get the returned value of a script. As user19752 suggested, the returned value could be written to a global field that is queried from a specific Layout

                       

                      I have a last question though: I seem to understand that the script I wish to call has to be set to an object on the layout set by the URL, unless it will not run. Is that right ?

                       

                      Thanks

                      • 8. Re: CWP with XML: executing a script
                        wimdecorte

                        planteg wrote:

                         

                        I have a last question though: I seem to understand that the script I wish to call has to be set to an object on the layout set by the URL, unless it will not run. Is that right ?

                         

                        Not correct.  You can call any script that the account has rights to.

                        • 9. Re: CWP with XML: executing a script
                          wimdecorte

                          planteg wrote:

                           

                          In Python, even though I execute the script with -findall (automatically added by the wrapper), I get only the first record, because the wrapper returns only the first record.

                           

                          That's very inefficient, I would change the Python code to use "-findany".  No reason why you would make the XML API return all records, have the Python call wait for it, only to then drop everything but the first record from the resulting set.  Better to just ask for one random record in the first place.

                          1 of 1 people found this helpful
                          • 10. Re: CWP with XML: executing a script
                            planteg

                            I seem to understand that the script I wish to call has to be set to an object on the layout set by the URL, unless it will not run.

                             

                            My error, the script I called was modifying a field not on the layout that was referred to .

                             

                            I agree that using -findall is not a good idea. I will edit the library to add -findany instead.

                             

                            Thanks to all.

                            • 11. Re: CWP with XML: executing a script
                              beverly

                              You may also get an error code returned which would appear in the raw XML.

                               

                              Sent from miPhone

                              • 12. Re: CWP with XML: executing a script
                                planteg

                                beverly ,

                                 

                                you are right, unfortunately the library does not return all that is in the raw XML. But when there is an error, it raises an error and then I can get the error number. Python has try/catch blocks like many others languages.

                                • 13. Re: CWP with XML: executing a script
                                  beverly

                                  I meant the error code that FM would generate for the xml request.

                                  beverly

                                  • 14. Re: CWP with XML: executing a script
                                    beverly

                                    is the script server and/or web compatible?

                                     

                                    & you might try the

                                    -findany

                                    rather than the

                                    -findall

                                     

                                    of course it may depend if your script needs to find something.

                                    do you need a

                                    -sort

                                    ?

                                    1 2 Previous Next