1

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

Bryan van Rijn
  • 837
  • 10
  • 18

1 Answers1

1

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 :)

Adam
  • 810
  • 7
  • 10
  • Hi Adam, thanks for your awnser. Yes, I finally do a executeQueryAsync, but my question is, why does it step out (stop with debugging)? I've rewrite the code a littlebit, so I get the context of a current HostWeb. var clientContext = new SP.ClientContext(spHostUrl); var oWebsite = clientContext.get_web(); // ===> Debugger steps out Now it steps out (stops with debugging) on the oWebsite... Can it have anything to do with the fact I'm trying to get the context in the AppWeb? – Bryan van Rijn Feb 21 '20 at 07:47