我正在使用C#CSOM代码创建Sharepoint列表视图。我使用ViewCreationInformation来创建我的视图。我在编写查询时遇到了问题。
写这个有用:
ViewCollection viewColl = list.Views;
string[] viewFields = {"Id", "Action", "Created", "Created By"};
ViewCreationInformation creationInfo = new ViewCreationInformation();
creationInfo.Title = "FromCode";
creationInfo.ViewFields = viewFields;
creationInfo.Query = @"<Where><Neq><FieldRef Name=""ConfidentialDocument""/><Value Type=""Choice"">No</Value></Neq></Where><GroupBy><FieldRef Name=""TemplateName"" /><FieldRef Name=""Title"" /></GroupBy><OrderBy><FieldRef Name=""Created"" Ascending=""True"" /></OrderBy>";
creationInfo.ViewTypeKind = ViewType.Html;
creationInfo.RowLimit = 30;
creationInfo.Paged = true;
creationInfo.SetAsDefaultView = true;
viewColl.Add(creationInfo);
但如果我将查询更改为:
creationInfo.Query = @"<Where><Neq><FieldRef Name=""ConfidentialDocument""/><Value Type=""Choice"">No</Value></Neq></Where><GroupBy Collapse=""TRUE"" GroupLimit=""30""><FieldRef Name=""TemplateName"" /><FieldRef Name=""Title"" /></GroupBy><OrderBy><FieldRef Name=""Created"" Ascending=""True"" /></OrderBy>";
然后视图显示错误: TypeError: Unable to get property 'substring' of undefined or null reference
您可以查看链接或这是错误: TypeError:无法获取属性&#39; substring&#39;未定义或空引用
TypeError: Unable to get property 'substring' of undefined or null referenceTypeError: Unable to get property '_events' of undefined or null reference
有没有人对此有任何想法?我搜索了很多地方,到处都找到了类似的代码。我不知道为什么这段代码不起作用。
答案 0 :(得分:1)
好的问题出在GroupLimit =&#34;&#34; 30&#34;&#34;。没有GroupLimit的查询工作完全正常。
creationInfo.Query = @"<Where><Neq><FieldRef Name=""ConfidentialDocument""/><Value Type=""Choice"">No</Value></Neq></Where><GroupBy Collapse=""TRUE""><FieldRef Name=""TemplateName"" /><FieldRef Name=""Title"" /></GroupBy><OrderBy><FieldRef Name=""Created"" Ascending=""True"" /></OrderBy>";