Using filtered options from REST API in a lookup field

Home Forums Classic DFFS Using filtered options from REST API in a lookup field

Viewing 14 reply threads
  • Author
    Posts
    • #37982
      Hao Wang
      Participant

        Hi all,

        We want to filter out the options in a lookup field in my form. We do not need cascading lookup as the lookup field already has an ID to use as the query criteria to reduce the number of options. We are able to obtain the results from the REST API. However, whenever I want to update the options in the lookup field, the update overwrites the field’s label instead. Anything I did wrong? Thanks.

      • #37983
        Alexander Bautz
        Keymaster

          If you can show me the code you use I can have a look at it.

          Alexander

        • #37984
          Hao Wang
          Participant

            Thanks. My code worked in the HTML snippet, so I am set for now. However, when I put in the Custom JS, it fails to run for unknown reasons, probably due to the timing issue. When I call the functions, it says they are not defined yet. I tried delay, polling, or window.onload, none worked.

          • #37990
            Alexander Bautz
            Keymaster

              Without looking at the code I’m not able to give you any recommendations on how to fix it.

              If you can attach the code as a txt-file I’ll take a look.

              Alexander

            • #37992
              Hao Wang
              Participant

                Thank you, Alex. I have attached two simple scripts. Neither worked in the Custom JS section, but both work if I include them in an HTML snippet.

                For now it works for me but it would be better if we can put them in Custom JS instead of HTML sections.

                Hao

              • #37993
                Hao Wang
                Participant

                  Here are the scripts in txt files.

                • #37998
                  Alexander Bautz
                  Keymaster

                    Thanks, can you also explain how / when you trigger the functions?

                    Alexander

                  • #37999
                    Hao Wang
                    Participant

                      I tried many ways. I tried using button clicks to call functions, entering the function name in a tab that allows me to run on clicking on the tab, and calling the function(s) in the rules “when the form is ready…” They all said that, in one way or another, the functions were not defined or found. There were no logs after I plugged in some console.log inside the scripts. These were when I put the files in the Custom JS and verified the paths were good.

                      However, the inline editing javascript you wrote ran seamlessly when I put it there. I scratched my head and believed I must have missed something.

                      Thanks for helping.

                    • #38005
                      Alexander Bautz
                      Keymaster

                        My first thought is that you had the code wrapped in a block (function or if-statement) so it was not available in the global window namespace, but without seeing your entire custom js code I cannot tell for sure.

                        In general you can add functions to the Custom JS code editor and call the functions from a button in a HTML section or by calling them from a rule.

                        Alexander

                      • #38010
                        Hao Wang
                        Participant

                          The sample Javascripts I sent you in those Txt files were used as the “entire” custom JS codes, yet we cannot call the functions in them from a button or a rule. You are right; they were not in the global window namespace. We tried to modify the function definition using a window.XXX, it did not work either. Thanks though. Now they are running in my embedded HTML sections, so we are okay with that.

                        • #38011
                          Hao Wang
                          Participant

                            I suspect it is the script loading issue, though we handled your inline editing Javascript in the same manner, and they work!

                          • #38012
                            Alexander Bautz
                            Keymaster

                              I have created a test config that you can import into a list. It will show you how to use the custom js and call one of the functions from a HTML section.

                              Create a new list with only the title field and install DFFS. Go to the Export, import and restore tab and import the config by copy pasting from the attached file.

                              Please note that the function will obviously not work in this test list because the target fields are missing.

                              It looks like my attachment plugin suddenly blocks txt files – trying again with a zip.

                              Alexander

                            • #38021
                              Hao Wang
                              Participant

                                Alexander; it is embarrassing that my site now lost the ability for us to create a new list and install the classic DFFS. The column type DFFS Loader by SPJSBlog.com is now missing from my site. Creating a column with that name won’t bring up the configuration I need. Any advice on how I can bring that configuration back? Thanks. Hao

                              • #38022
                                Hao Wang
                                Participant

                                  Alexander, thanks. I recreated the installer, installed DFFS on a new list, and then imported your config. How you configured it works by including the script in the editor window of the Custom JS tab.

                                  Instead of pasting the JavaScript into the Custom JS editor window, I used the text area above to include my script as a file, and the file path verified OK. It stopped working.

                                  I included your inline editing script as a file; it works there. I am curious what is going on.

                                  Hao

                                  By the way, how can I recover the production license installed by SP Services? While I tried to recreate the classic installer, the message of the trial period appeared in the configuration window for the new test list. The old lists still work with the production license.

                                  • #38023
                                    Alexander Bautz
                                    Keymaster

                                      Not sure why it did not work when you used a file, but based on the fact that you use the old JSLink installer, I assume you use an older version of DFFS. If you hover over the Enhanced with DFFS link below the form and click the License and version information link you can see the version numbers.

                                      The SP Services license is an OEM license for the core functionality that they deliver. This means you cannot use that license for additional lists that are not part of the package delivered by SP Services.

                                      If you want to use DFFS in additional sites you must purchase a site or site collection license.

                                      Alexander

                                  • #38025
                                    Hao Wang
                                    Participant

                                      Ok. I already bought a site collection license for the modern version of the DFFS. We will rewrite our own app and retire the SP app using the old version of the DFFS soon. You showed me how to put the JavaScript in the Custom JS editor window, which is better than putting it in the HTML snippet. We had thought that Custom JS did not work at all. Thanks.

                                  Viewing 14 reply threads
                                  • You must be logged in to reply to this topic.