I have created a survey list. I need to change the redirection from QstNew.aspx page to Overview.aspx.

For this purpose,I require list name to be fetched dynamically.

I can get the list GUID from the QstNew.aspx page URL.I need to get the List name from the GUID.

Can anyone give the answers...or suggest how to get the current list name using Javascript

Thanks!!

up vote 9 down vote accepted

You can use the below rest call as well.:

Replace guid with your list guid.

$.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid 'b778bbec-dd69-4a6c-9437-c73972c36292')",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            console.log("List Title :" + data.d.Title);
        },
        error: function (data) {
            console.log(data);
        }
  });
  • This worked for me.!! Thanks Gautam – NivethaSri Jan 4 '17 at 8:54

Using Client Object Model will help in this case:

var oList;

function getListTitleById() {
    var clientContext = SP.ClientContext.get_current();

    oList = clientContext.get_web().get_lists().getById(__ID of the list__);

    clientContext.load(oList,"Title");

    clientContext.executeQueryAsync(
            Function.createDelegate(this, this.onQuerySucceeded), 
            Function.createDelegate(this, this.onQueryFailed)
        );
}

function onQuerySucceeded(sender, args) {
    alert('Title: ' + this.oList.get_title());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

Where oList is a global variable.

  • I need to do it using Javascript. Can you give the suggestions for doing this through javascript? @Adam – NivethaSri Jan 4 '17 at 6:19
  • 1
    This is JSOM, meaning JavaScript Object Model for SharePoint. Do you mean without using JSOM? – Arsalan Adam Khatri Jan 4 '17 at 6:21
  • Yes.I meant without usinh jsom @adam khatri – NivethaSri Jan 4 '17 at 7:34

We can also achieve this by using PnP JS library. This is open source javascript framework contains lot of utility and helper methods based on SharePoint REST API.

<script type='text/javascript' src='https://raw.githubusercontent.com/SharePoint/PnP-JS-Core/master/dist/pnp.min.js'></script>

Include pnp js file to your application and call the below script to get the List title based on Guid.

$pnp.sp.web.lists.getById("D9DD0889-3F17-4A57-8B4C-4C8A475680D1").get().then(function(res) {
    console.log("List Title: " + res.Title);
});

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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