0

One of the Projects I am working on, I have a requirement to read the current Sharepoint library name using JSOM (should be dynamic in nature). I have to show it in a web part so if someone knows how to achieve that via JSOM approach, please help me with the line of code.

Thanks in advance.

1

You can use the following scripts to get the title of the current list/library that the user is working on:

function getListName(){
        SP.SOD.executeFunc("sp.js", "SP.ClientContext", function () {
        SP.SOD.executeFunc("sp.core.js", "SP.ListOperation.Selection",
        function () {   
           var listId = SP.ListOperation.Selection.getSelectedList();
           console.log(listId);     
           if (typeof (listId) == "undefined" || listId == null || listId == "") {
               return;
           }
           var ctx = SP.ClientContext.get_current();
           var list = ctx.get_web().get_lists().getById(listId);
           ctx.load(list);
           ctx.executeQueryAsync(
               Function.createDelegate(this, function (sender, args) {
                   console.log("current list/library name: "+list.get_title());
                   alert(list.get_title());
               }),
               Function.createDelegate(this, function (sender, args) {
                   console.log(args.get_message());
               })
           );
       });
  });
}

Refer to: http://sadomovalex.blogspot.com/2016/08/get-title-of-current-list-in-sharepoint.html

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.