none
how to split string type field value in sharepoint list item using jquery RRS feed

  • Question

  • Hi Team,

    I have a fairly simple issue. I have created a script editor web part and uploaded the below code to retrieve and display the SharePoint list item. I am getting the value "undefined" when i try to retrieve the look up column value in SP list which holds set of strings. (tex1 ; text2; text3). How to achieve this?

    <script type="text/javascript" src="filelink/jquery-1.4.2.min.js"></script>

    //to download SPServices click here <script type="text/javascript" src="filelink/jquery.SPServices-0.5.4.min.js"></script> <script language="javascript" type="text/javascript"> $(document).ready(function() { $().SPServices({ operation: "GetListItems", async: false, listName: "Announcements", CAMLViewFields: "<ViewFields><FieldRef Name='LookupColumn' /></ViewFields>", completefunc: function (xData, Status) { $(xData.responseXML).find("[nodeName='z:row']").each(function() { var liHtml = "<li>" + $(this).attr("ows_LookupColumn") + "</li>";

    alert(liHtml);

    $("#tasksUL").append(liHtml); }); } }); }); </script> <ul id="tasksUL"/>

     Thanks in advance.


    • Edited by Jo.nec Friday, December 23, 2016 11:01 AM
    Friday, December 23, 2016 11:01 AM

All replies

  • Hi Jo.nec,

    We can split the lookup field xml to get the lookup text like below:

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="http://sp/sites/team/Shared%20Documents/jquery.SPServices-2014.02.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
      $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Resume",
        CAMLViewFields: "<ViewFields><FieldRef Name='job' /></ViewFields>",
        completefunc: function (xData, Status) {
          $(xData.responseXML).SPFilterNode("z:row").each(function() {
            console.log($(this).attr("ows_job").split(";#")[1]);
          });
        }
      });
    });
    </script>
    

    In the code demo above, my lookup column called job and the xml like below:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Monday, December 26, 2016 7:18 AM
  • Hi Jo,

    Is there anything updates ? If my reply is helpful to this question, please mark it as answer so that it can help others who stuck with the same question in the forum.

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Friday, December 30, 2016 2:53 AM