0

I found several articles about how to get a single value from a sharepoint custom list, but I am new to javascript and so I cound't implement them to my situation.

I belive what is want is quite simple: I have a list with 2 column Name and ID. The use enter the ID (what is a unique value) in a new form (different from the list's new form) to a textbox and the Name from the same row appears in an other textbox. So:

  1. User enter the ID to a textbox and press enter/click out/ect.

  2. Based on the enterred ID the script search in the targeted list's ID column for the ID.

  3. If the ID exist the Name's value from the same row inserted to an empty textbox in the form where the user enterred the ID to the first textbox.

Sounds easy but even after several attempt I only got [object Obecjet], [object promises] ect. And finaly when I tought it should work I got a random text "Next Page" insted of the Name so probably I am doing something wrong. So I would be glad if someome who experienced would show me an example code for this situation.

I add my code too, it is not contains errors, but give me the "Next Page" instead of working well:

< script type = script type="text/javascript "src = ".../SiteAssets/jquery.min.js" > < /script>
< script type = "text/javascript "src".../SiteAssets/nanoajax.min.js" > < /script>
< script type = "text/javascript "src".../SiteAssets/sharepointplus-4.0.min.js" > < /script>
< script type = "text/javascript" >
          $(function() {
            $SP().list("TargetListTitle").get({
              fields: "NameColumnTitle",
              where: 'IDColumnTitle = 101'
            }).then(function(res) {
              for (var key in res) {
                $("input[id='EmptyTextfieldID']").val(key);
              }
            });
          });
< /script>

Thanks you very much for your kind guidance!

1

Try this.

You don't need nanoajax.min.js. jQuery is enough.

If you changed "Title" column's name to "Name", you should use Title instead of Name.

< script type = "text/javascript "src = ".../SiteAssets/jquery.min.js" > < /script>
< script type = "text/javascript "src".../SiteAssets/sharepointplus-4.0.min.js" > < /script>
< script type = "text/javascript" >

$(document).ready(function () {

//If you know element, use #. 

$("#IDTextFieldID").on('keyup', function (e) {
    if (e.keyCode == 13) {//Detect if enter pressed

        //Query the sharepoint list
        $SP().list("TargetListTitle", "http://www.spsitecollectionaddress.com/").get(
        {
            fields: "ID,Name",
            where: 'ID = "101"'
        },
        function getData(data) {

            //Set return value to empty text box
            for (var i = 0; i < data.length; i++) {

                $("#NameTextFieldID").val(data[i].getAttribute("Name"));
            }

        });

    }
});


});

< /script>
  • Thank you very much for your help! I am testing it now. It contains no errors, but no result in the targeted textbox, and even if I set an alert inside the "for" not activate so I suspect targetting problems. May I ask you: 1. If my targeted list is "hu-shrp-form-d.sanofi.com/sites/Registry/Lists/INNList" then what should I add to replace the "spsitecollectionaddress.com"? 2. If my ID is a number do I need to convert the input to number too or it works with the "101"? 3. The lists's name is their displayname or their name from the URL? Thank for your help and sry for the trouble. – Nefri Oct 3 '17 at 8:12
  • Yeah looks like the data.length is 0, that is the reason the "for" not works, but I can't find why. I excluded the input part to make it more simple and I created a very simple test list with only text fields and the display/url names are the same + don't have any specific characters so the list targeting should be fine too. The remaining issue can be the URL or someting I don t think of. Now it is looking like this: jsfiddle.net/zetvtn7m – Nefri Oct 3 '17 at 9:03
  • 1
    1 - You should provide "hu-shrp-form-d.sanofi.com/sites/Registry" for the site address. 2 - I'm not sure but ID can be "101" or 101. Can you try both? 3 - List name is the display name of the list, not the name in the url. – newbie Oct 3 '17 at 9:08
  • Yeah I am testing all the way possible :) I excluded problem 2. and problem 3. I set the URL as you mentioned and I got an error: "hu-shrp-form-d.sanofi.com/sites/Registry/_vti_bin/Lists.asmx Failed to load resource: the server responded with a status of 500 (Internal Server Error)" Can it be permission problem? If I simply enter the same URL to my browser my SP home page appear with no problem, so quite strange, but I am new to both SP and JS so I may not noticing something trivial, but important. – Nefri Oct 3 '17 at 9:24
  • Nope, it is not a permission problem. You should type http:// too. And be sure that there is no " " blank character at the end of the url. Also be sure that there is no blank character at the name of your list. SharePointPlus hates spaces :) – newbie Oct 3 '17 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.