Sharepoint - How to get List name by its GUID using Javascript
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.
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);
}
});
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);
});