指定的参数超出了有效值的范围。参数名称:索引
Specified argument was out of the range of valid values. Parameter name: index
我有以下 javascript 代码,它必须从共享点管理的元数据存储中加载术语集。
代码在星期一之前一直运行良好,突然停止运行并出现标题错误。
我只用 console.log 更改了 executequeryasync 的内容,但我仍然有错误。
我已经逐行调试了 execGetTermIds,none 行抛出了异常
function GetTermsDataFromTaxonomy(){
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");
//GUID of Term Set from which to get the Terms.
var termSet = termStore.getTermSet("31da4bc1-6429-499a-9d5e-be5e18b13c87");
var terms = termSet.getAllTerms();
var list;
var p = execGetTermIDs();
p.done(function(result) {
context.load(terms);
context.executeQueryAsync(function(){
console.log("hola");
},
function(sender,args){
console.log(args.get_message());
});
});
p.fail(function(result) {
// result is a string because that is what we passed to reject()!
var error = result;
console.log(error);
});
}
function sortTermsFromTree (tree) {
if (tree.children.length && tree.term.get_customSortOrder) {
var sortOrder = null;
if (tree.term.get_customSortOrder()) {
sortOrder = tree.term.get_customSortOrder();
}
// If not null, the custom sort order is a string of GUIDs, delimited by a :
if (sortOrder) {
sortOrder = sortOrder.split(':');
tree.children.sort(function (a, b) {
var indexA = sortOrder.indexOf(a.guid);
var indexB = sortOrder.indexOf(b.guid);
if (indexA > indexB) {
return 1;
} else if (indexA < indexB) {
return -1;
}
return 0;
});
}
// If null, terms are just sorted alphabetically
else {
tree.children.sort(function (a, b) {
if (a.title > b.title) {
return 1;
} else if (a.title < b.title) {
return -1;
}
return 0;
});
}
}
for (var i = 0; i < tree.children.length; i++) {
tree.children[i] = sortTermsFromTree(tree.children[i]);
}
return tree;
}
function execGetTermIDs(){
var d = $.Deferred();
var q = "<View><Query><Where></Where></Query></View>";
var context = new SP.ClientContext(siteUrl);
var oList = context.get_web().get_lists().getByTitle('TaxonomyHiddenList');
var camlQuery = SP.CamlQuery.createAllItemsQuery();
var collTermListItem = oList.getItems(camlQuery);
context.load(collTermListItem);
var o = {d: d, collTermListItem:collTermListItem};
context.executeQueryAsync(
Function.createDelegate(o, getTermIDsComplete),
Function.createDelegate(o, failCallback)
);
return d.promise();
}
function getTermIDsComplete()
{
var listItemEnumerator = this.collTermListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
termIDs[oListItem.get_fieldValues().Title] = oListItem.get_id();
}
this.d.resolve(termIDs);
}
function failCallback() {
this.d.reject("something bad happened");
}
我的天啊,我发现了这个错误,我找不到解释,希望微软的人能告诉我。
这一行:
var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");
我们注意到名称现在不同了,它有不同的 GUID,但我们作为客户无法更改该名称,所以唯一的原因是微软为我们更改了它,因为它在星期一工作。
更新:我更改了该行:
termStore = session.getDefaultSiteCollectionTermStore();
避免以后再发生。
我有以下 javascript 代码,它必须从共享点管理的元数据存储中加载术语集。 代码在星期一之前一直运行良好,突然停止运行并出现标题错误。
我只用 console.log 更改了 executequeryasync 的内容,但我仍然有错误。
我已经逐行调试了 execGetTermIds,none 行抛出了异常
function GetTermsDataFromTaxonomy(){
//Current Context
var context = SP.ClientContext.get_current();
//Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
//Term Stores
var termStores = taxSession.get_termStores();
//Name of the Term Store from which to get the Terms.
var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");
//GUID of Term Set from which to get the Terms.
var termSet = termStore.getTermSet("31da4bc1-6429-499a-9d5e-be5e18b13c87");
var terms = termSet.getAllTerms();
var list;
var p = execGetTermIDs();
p.done(function(result) {
context.load(terms);
context.executeQueryAsync(function(){
console.log("hola");
},
function(sender,args){
console.log(args.get_message());
});
});
p.fail(function(result) {
// result is a string because that is what we passed to reject()!
var error = result;
console.log(error);
});
}
function sortTermsFromTree (tree) {
if (tree.children.length && tree.term.get_customSortOrder) {
var sortOrder = null;
if (tree.term.get_customSortOrder()) {
sortOrder = tree.term.get_customSortOrder();
}
// If not null, the custom sort order is a string of GUIDs, delimited by a :
if (sortOrder) {
sortOrder = sortOrder.split(':');
tree.children.sort(function (a, b) {
var indexA = sortOrder.indexOf(a.guid);
var indexB = sortOrder.indexOf(b.guid);
if (indexA > indexB) {
return 1;
} else if (indexA < indexB) {
return -1;
}
return 0;
});
}
// If null, terms are just sorted alphabetically
else {
tree.children.sort(function (a, b) {
if (a.title > b.title) {
return 1;
} else if (a.title < b.title) {
return -1;
}
return 0;
});
}
}
for (var i = 0; i < tree.children.length; i++) {
tree.children[i] = sortTermsFromTree(tree.children[i]);
}
return tree;
}
function execGetTermIDs(){
var d = $.Deferred();
var q = "<View><Query><Where></Where></Query></View>";
var context = new SP.ClientContext(siteUrl);
var oList = context.get_web().get_lists().getByTitle('TaxonomyHiddenList');
var camlQuery = SP.CamlQuery.createAllItemsQuery();
var collTermListItem = oList.getItems(camlQuery);
context.load(collTermListItem);
var o = {d: d, collTermListItem:collTermListItem};
context.executeQueryAsync(
Function.createDelegate(o, getTermIDsComplete),
Function.createDelegate(o, failCallback)
);
return d.promise();
}
function getTermIDsComplete()
{
var listItemEnumerator = this.collTermListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
termIDs[oListItem.get_fieldValues().Title] = oListItem.get_id();
}
this.d.resolve(termIDs);
}
function failCallback() {
this.d.reject("something bad happened");
}
我的天啊,我发现了这个错误,我找不到解释,希望微软的人能告诉我。
这一行:
var termStore = termStores.getByName("Taxonomy_kl5tZjInn7STsFTzIE7n3Q==");
我们注意到名称现在不同了,它有不同的 GUID,但我们作为客户无法更改该名称,所以唯一的原因是微软为我们更改了它,因为它在星期一工作。
更新:我更改了该行:
termStore = session.getDefaultSiteCollectionTermStore();
避免以后再发生。