简体   繁体   中英

How to retrieve a Document Library by it's ID in SharePoint using jquery

I've a custom action on the CommandUI.Ribbon. It triggers a SharePoint add-in and sends the ListID allong as parameter.

In the Add-in page, I try to upload a document (from a rest service).

When I try to get the document library by it's ID, it steps out of the debugger and I have no clue why.

var ctx = SP.ClientContext.get_current();
var fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(documentName);
fileCreateInfo.set_overwrite(true);
fileCreateInfo.set_content(content);

var parentList = ctx.get_web().get_lists().getById(listId);  //steps out here. 

Is it possible that the getById method doesn't exist?

Hope to hear from you guys and girls...

if You plan to use JSOM to query the list from SharePoint You should also do the executeQuery. The flow of using JSOM is:

  1. getting the context
  2. loading what You need into the context
  3. execute the query to initialize the objects
  4. in the success of the query get the data You need.

Please refer to this msdn article for more information

I suppose for Your needs this kind of solution might work



    function retrieveAllListProperties() {

        var clientContext = SP.ClientContext.get_current();
        var oWebsite = clientContext.get_web();
        this.collList = oWebsite.get_lists().getById('[PLACE LIST GUID HERE]');

        clientContext.load(collList);

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

    function onQuerySucceeded() {
        console.log(collList.get_title());
    }

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

If You have the proper context were the list is present and the needed permissions the output of running retrieveAllListProperties() should be the title of the queried list.

I hope this will be of any help :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM