I am creating a Sharepoint List View using C# CSOM code. I'm using ViewCreationInformation to create my view. I'm facing problem in writing the query for it.
Writing this works:
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);
But If I change the query to this:
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>";
Then the View displays an error: TypeError: Unable to get property 'substring' of undefined or null reference
You can check the link or here is the error: TypeError: Unable to get property 'substring' of undefined or null reference
TypeError: Unable to get property 'substring' of undefined or null referenceTypeError: Unable to get property '_events' of undefined or null reference
Does anyone have any idea about this? I've searched many places and I found similar codes everywhere. I don't know why this code is not working.
Ok the problem was with GroupLimit=""30"". Query without GroupLimit works totally fine.
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>";