0

Can someone help me?

I tried to write an add-in. The add-in contains 2 pages (default and init), a JS module and add a button to the documentlist part.

When user selects a folder and clicks the button, the button open the init page (CommandAction="~appWebUrl/Pages/Init.aspx?{StandardTokens}&SPListItemId={SelectedItemId}&SPListId={SelectedListId}"/>) that contains some textboxes and a button.

This button calls a JS function that display the names of the documents in the folder.

But while executing the function, the clientContext.executeQueryAsync(OK, Err) function never fire the callbacks and never display any error messages.

I tried different syntax for the success and error functions but the result is the same.

What am I doing wrong?

simplified code

'use strict'; ExecuteOrDelayUntilScriptLoaded(TestParam, "sp.js");

var allDocumentsCol; function onSucceededCallback(sender, args) { var ListEnumerator = allDocumentsCol.getEnumerator(); while (ListEnumerator.moveNext()) { var currentItem = ListEnumerator.get_current(); console.log(currentItem.id); } }

function onFailedCallback(sender, args) { console.log("failed. Message:" + args.get_message()); }

function createInfos() { var hostWebContext = new SP.AppContextSite(clientContext, hostWebURL); var list = hostWebContext.get_web().get_lists().getById(listId); var caml = SP.CamlQuery.createAllItemsQuery(); caml.set_viewXml("Folder"); allDocumentsCol = list.getItems(caml); clientContext.load(allDocumentsCol, "Include(FileLeafRef, ServerUrl)"); clientContext.executeQueryAsync(onSucceededCallback, onFailedCallback); }

// Utility functions function getQueryStringParameter(paramToRetrieve) { var params = document.URL.split("?")[1].split("&"); for (var i = 0; i < params.length; i = i + 1) { var singleParam = params[i].split("="); if (singleParam[0] == paramToRetrieve) { return singleParam[1]; } } }

// params en entrée function GetPageParams() { itemId = decodeURIComponent(getQueryStringParameter("SPListItemId")); listId = decodeURIComponent(getQueryStringParameter("SPListId")); } function TestParam() { GetPageParams(); if (itemId === 'null') { alert('sélectionnez un folder svp'); } if (itemId.includes(',')) { alert('sélectionnez un seul folder svp'); } }

var clientContext; var hostWebURL; var hostWebContext;

var itemId; var listId;

// Command start function createLink() { clientContext = SP.ClientContext.get_current(); hostWebURL = decodeURIComponent(getQueryStringParameter("SPHostUrl")); createInfos(); }

1
  • Can you add the code you are using to your original question by editing it? Mar 9 at 8:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.