12

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!!

3 Answers 3

13

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);
        }
  });
0
11

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.

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

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

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.