7

How can I get default display form url of sharepoint list item via Rest or JSOM. I found the result by link: How to get the Display Form URL, using REST

But the XML returns all of the display form url, I don't know how to specify where is the default URL?

I need to get it dynamically!

2 Answers 2

10

You could also use

_api/Web/Lists/GetByTitle('List title')/DefaultDisplayFormUrl

If you want for all lists do

_api/Web/Lists?$select=DefaultDisplayFormUrl

Note that the property is not visible when visiting List directly, need full path or $select.

3
  • Hi again, how can I get the results. I use data.d.results[0].DefaultDisplayFormUrl, but it doesn't work Commented Nov 17, 2014 at 7:03
  • Try data.value. It could alter if you use SPO, on premise or through an app. What you can do is to call console.log(data) and you will see the object structure in say Chrome dev tools. Another option is to view it in Dev tools network tab. Yet another is to set break point and inspect data variable. Commented Nov 17, 2014 at 7:10
  • Thanks guy, console.log(data) work perfect then I can inspect the object. Great! Commented Nov 17, 2014 at 7:14
5

Use DefaultDisplayFormUrl at the time of loading the list in Javacript client object model. Example:

var clientContext = new SP.ClientContext.get_current();
var list = clientContext.get_web().get_lists().getByTitle(listTitle);
clientContext.load(list, 'DefaultDisplayFormUrl');

Then while enumerating the listitemcollection use get_defaultDisplayFormUrl() to create the Url. Example:

while (listItemEnumerator.moveNext()) {
    var listItem = listItemEnumerator.get_current();
    var listItemId = listItem.get_item('ID');
    var href = list.get_defaultDisplayFormUrl() + "?ID=" + listItemId;
    }
1
  • i also used the same one but it gives mi url like href="/sites/appdev/Lists/Students" List dispform.aspx?id="14"></a> and my list name is "Students List" and this is my code var web = context.get_web(); //Get the Site ListName = "Students List"; ListName = ListName.trim(); var list = web.get_lists().getByTitle(ListName); var query = new SP.CamlQuery(); var items = list.getItems(query); ctx.load(list, "DefaultDisplayFormUrl"); ctx.load(items); Commented Sep 30, 2016 at 5:45

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.