0

I'm trying to return value from a LookUp value to my dataTables. The only thing that returns is [object Object].

Here is an image of my List and result: enter image description here

I searched that I should add $expand in my URL line however that did not work. Any suggestions? As you can I see I am having issues with my HyperLink column as well but I think I saw a solution on StackExchange so I'll look at that first.

Here is my code:

        <script>
        $(document).ready(function(){
            GetItems();
        });
        
        function GetItems(){
            //var siteUrl=_spPageContextInfo.webAbsoluteUrl;
            var siteUrl="https://whatever.com";
            var oDataUrl = siteUrl + "/_api/web/lists/getbytitle('datatabletest')/items?$select=Title,HyperLink,LookUp/Title&$expand=LookUp/Title";
            $.ajax({
            url:oDataUrl,
            type:"GET",
            dataType:"json",
            headers:{
            "accept":"application/json;odata=verbose"
            },
            
            success:OnSucces,
            error:OnFailure
            });
        }
        
        function OnSucces(data){
            try{
                $('#example').DataTable({
                    "aaData":data.d.results,
                    "aoColumns":[
                    {"mData":"Title"},
                    {"mData":"HyperLink"},
                    {"mData":"LookUp"}
                    ]
                });
            }
            catch(e){
                alert(e.message);
            }
        }
        
        function OnFailure(data, errMessage){
            alert("Error: " + errMessage);
        }
    </script>

1 Answer 1

0

I was able to figure it out. Changed:

{"mData":"LookUp"}

to

{"mData":"LookUp.Title"}
1
  • 1
    Similarly, you can change HyperLink to HyperLink.Url. Commented Dec 28, 2021 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.