7

How to get the current list/library name using JSOM? So far I found two snippets which return GUID of the current list/library, but not the name.

// Using standard JSOM
SP.ListOperation.Selection.getSelectedList()

// Using SP Services
$().SPServices.SPListNameFromUrl()

I would prefer something which would not go for server callbacks.

11

Use ctx to get current list/library info. For Name or Title, It is

ctx.ListTitle

PS: No callback needed

Following information can be retrieved from ctx about current list/library in SharePoint 2010.

 [   "listBaseType", "listTemplate", "listName", "view", "listUrlDir",
    "HttpPath", "HttpRoot", "serverUrl", "imagesPath", "PortalUrl",
    "RecycleBinEnabled", "isWebEditorPreview", "rootFolderForDisplay",
    "isPortalTemplate", "isModerated", "recursiveView", "displayFormUrl",
    "editFormUrl", "newFormUrl", "ctxId", "CurrentUserId", "isForceCheckout",
    "EnableMinorVersions", "ModerationStatus", "verEnabled", "isVersions",
    "WorkflowsAssociated", "ExternalDataList", "HasRelatedCascadeLists",
    "CascadeDeleteWarningMessage", "ContentTypesEnabled", "SendToLocationName",
    "SendToLocationUrl", "StateInitDone", "TotalListItems", "CurrentSelectedItems",
    "LastSelectableRowIdx", "SelectAllCbx", "TableCbxFocusHandler", "TableMouseoverHandler",
    "existingServerFilterHash", "NavigateForFormsPages", "OfficialFileName", "OfficialFileNames",
    "WriteSecurity", "SiteTitle", "ListTitle", "isXslView", "clvp"
]

To find above info, paste the following line in browser's console.

console.dir(Object.keys(ctx))

Unfortunately, It is not documented by MSDN. The all we have for exploring it is: Browser's console.

  • You mean like this SP.ClientContext.get_current().ListTitle? – Naveen Dec 28 '15 at 10:58
  • No ... It will return the currently opened list in the browser. Try it in the browser console – Atish Dipongkor Dec 28 '15 at 11:00
  • Nopes, ctx is an list object having almost every data present in the list. You need to just write :- var listtitle=ctx.ListTitle; – Azam Khan Dec 28 '15 at 11:01
  • @AtishDipongkor sorry i didnt saw ur comment – Azam Khan Dec 28 '15 at 11:02
  • 2
    ctx is only availble on list view pages, not on list item forms, unfortunately. Not sure if it's relevant, but make sure you double check. – Alexey Krasheninnikov Dec 28 '15 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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