我目前正在开发一个Office插件,该插件将检查单词doc以获取内容控件,并将获取这些内容控件的名称和标记,并对SharePoint进行休息调用以检查Mod Dates。我目前正在加载标签和标题而没有问题,我的问题是,如果我发现mod日期不一样,我希望能够加载特定的内容控件。
当前代码
function loadContentControls() {
Word.run(function (context) {
var contentControlProperties = [];
var contentControls = context.document.contentControls;
context.load(contentControls, "id");
return context.sync().then(function () {
if (contentControls.items.length > 0) {
for (var x = 0; x < contentControls.items.length; x++) {
contentControls.items[x].load('title,' + "tag");
}
}
else {
$("#notificationBody").html("<h4>No Update Found</h4>");
messageBanner.showBanner();
messageBanner.toggleExpansion();
}
return context.sync().then(function (e) {
for (var x = 0; x < contentControls.items.length; x++) {
contentControlProperties.push({
Name: contentControls.items[x].title,
Moddate: contentControls.items[x].tag,
});
}
return context.sync().then(function () {
var url;
var unParsedDateTime;
var parsedDateTime;
for (var i = 0; i < contentControlProperties.length; i++) {
url = "https://tenant/sites/ContentCenter/_api/web/Lists/GetByTitle('kist')/items?select=Title,Title&$filter=Title eq '" + contentControlProperties[0].Name + "'";
authContext.acquireToken(config.endpoints.SharePoint, function (error, token) {
if (error || !token) {
console.log('error');
return;
}
else {
$.ajax({
type: "GET",
url: url,
headers: {
"Authorization": "Bearer " + token,
"accept": "application/json;odata=verbose"
},
success: function (data) {
unParsedDateTime = new Date(data.d.results[0].Modified);
parsedDateTime = unParsedDateTime.toLocaleDateString('en-US').concat(' ' + unParsedDateTime.getHours() + ':' + unParsedDateTime.getMinutes());
>> So if there is a date discrepancy I would like to grab that specific content control here
},
error: function (error) {
console.log("Fetching list from SharePoint failed.");
}
})
}
});
}
})
})
})
.catch(function (error) {
error.ErrorLocation = "Inserting Content To Doc";
error.ErrorCode = error.debugInfo.errorLocation;
error.ErrorMessage = "Could Not Insert Image";
error.Selection = selectedContents.Name;
ErrorHandler(error);
})
})
}
答案 0 :(得分:0)
我甚至无法通过id加载特定的内容控件,我认为这是可能的。所以我继续前进并制作了一个我在context.sync().then()
内打电话的违约物品。这可行的方式是When my Token get back from adal I will go ahead and execute the for loop
。这将确保我的SharePoint响应正常,如下面的代码所示。因此,不是回去实际加载特定的内容控件,而是可以将它全部保存在ajax调用中,当两次不同时,我可以将该特定内容控件赋予红色背景。
return context.sync().then(function (e) {
$.when(TokenForSharePoint()).then(function (sharepointToken) {
if (sharepointToken === "Error") {
authContext.login();
}
else {
for (var x = 0; x < contentControls.items.length; x++) {
itemUrl = "https://tenat.com/sites/*site*/_api/web/Lists/GetByTitle('*list*')/items?select=Title,Title&$filter=Title eq '" + contentControls.items[x].title + "'";
$.ajax({
type: "GET",
async: false,
url: itemUrl,
headers: {
"Authorization": "Bearer " + sharepointToken,
"accept": "application/json;odata=verbose"
},
success: function (data) {
var localDocTest = new Date(data.d.results[0].Modified);
var spText = new Date(contentControls.items[0].tag);
if (localDocTest != spText) {
// I will highlight the content control
}
},
error: function (error) {
console.log("Fetching list from SharePoint failed.");
}
})
}
}