I am using REST API to read items from a list and display it on a page in a table. I added an extra column and added an edit link which will take the user to another page and passing the id of the item to edit.

Something strange is happening though, when the user clicks on the link, it takes them to a different page even though the correct link shows in the URL. It's supposed to take them to a page with a form with data in the fields but it doesn't.

function onQuerySucceeded(data) {

    if(data.d && data.d.results){
        var items = data.d.results
        var listItems = '<table>'
            listItems += '<tr>'
            listItems += '<th>Update</th>'
            listItems += '<th>Service</th>'
            listItems += '<th>Permanent</th>'
            listItems += '<th>Itinerant</th>'
            listItems += '<th>Region</th>'
            listItems += '</tr>'            

        for (var x = 0; x < items.length; x++) {
            listItems += '<tr>'
            listItems += '<td><a href="https://xxxxxxx.sharepoint.com/sites/demos/mdemos/SitePages/editFormRestAPI.aspx?id='+items[x].ID+'">edit</a></td>'   //<----
            listItems += '<td>' + items[x].Title + '</td>'
            listItems += '<td>' + items[x].Permanent + '</td>'
            listItems += '<td>' + items[x].Itinerant + '</td>'
            listItems += '<td>' + items[x].Region + '</td>'
            listItems += '</tr>'
            listItems += '</table>'

    document.getElementById("service").innerHTML = listItems

I noticed when I remove the id from the url, the correct page with the form appears but doesn't when I add the id back to the url.

Any idea why this is happening?

1 Answer 1


That's what id works in SharePoint. When you add the id parameter in the end of the url, it would take you to the page with the corresponding id.

For example, url is https://yoursite/SitePages/test.aspx?id=5

It would not go to the test.aspx in SitePages library, you would go to the page which id is 5 in the SitePages library.

So avoid adding id in the pageurl, you could use itemid instead of id to construct the url.

  • Thank you! I did not know that. Learned something.
    – OLA
    Commented Feb 11, 2021 at 2:33

Your Answer

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

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