locked
Querystring and REST services RRS feed

  • Question

  •   Hi,

    I have a custom list and visual webpart.

    I am trying to use the REST services to fetch data from the custom list and showing it in various fields of visual webpart.

    The  call to the webpart has a querystring variable. I am trying to get the data from the custom list based on this querystring.

    Example: servername/sitename/_vti_bin/ListData.svc/CustomList is my current URL.

    The call to visual webpart is like this: servername/sitename/sitepages/testpage?ItemID=01

    If ItemID =01, then get the item which matches ItemID in the custom list.

    How to change the REST url based on the querystring?

    Thanks

    Friday, June 7, 2013 1:27 PM

Answers

  • Below is  some java script to get the value of a query string variable. Once you have done this you can do a string replace of the text between the parentheses.

    function getQueryStringParameter(p) {
        var params =
                document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == p)
                return singleParam[1];
        }
    
    }


    Blog | SharePoint Field Notes Dev Tool | ClassMaster

    • Marked as answer by Venkatzeus Tuesday, June 11, 2013 8:40 AM
    Saturday, June 8, 2013 3:01 AM

All replies