カレンダービューが追加されたイベントを表示しないのはなぜ私のCAMLに問題がありますか?
-
28-09-2020 - |
質問
私のコードはかなり前進しています。カレンダーリストとカレンダーのビューをいくつか作成します。
カスタム連絡先リスト内の各連絡先の1つのビューを作成します(その人のログインユーザー名を含む「ユーザー」フィールドを含む)。
これはすべて Provider Hosted App を起動すると作成されます。
これは、カレンダーイベントを追加すると、ビューでそのイベントを見ることができるはずです。 [カスタムカレンダーのユーザー]フィールドで、私の場合はユーザー名 "Developer"を追加しました。 (写真を見てください)
Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, Request.LogonUserIdentity))
{
Web web = clientContext.Web;
ListCreationInformation listCreator = new ListCreationInformation();
listCreator.Title = "CompanyCalendar";
listCreator.Description = "Workcalendar";
listCreator.TemplateType = (int)ListTemplateType.Events;
List ifListExcists;
// ValidateList() is a custom method to validate if the list already excists
if (!ValidateList(clientContext, listCreator.Title, out ifListExcists))
{
List calList = web.Lists.Add(listCreator);
clientContext.ExecuteQuery();
testLabel.Text = "The " + listCreator.Title + " list was created";
//Get my custom contactlist that contains a User field that contains the login username of that contact
List contactList = web.Lists.GetByTitle("Contacts");
CamlQuery query = CamlQuery.CreateAllItemsQuery();
Microsoft.SharePoint.Client.ListItemCollection collection = contactList.GetItems(query);
clientContext.Load(collection);
clientContext.ExecuteQuery();
foreach (var thisPerson in collection)
{
//Find the username for this user in cantactlist
var loggedInUserName = thisPerson["loggedInUser"];
//Get the internal name for LastName field (Which is the only Required field in this list) in the contactlist just for testing
string currentUserName = thisPerson["Title"].ToString();
//Create a new CalendarView
ViewCreationInformation newView = new ViewCreationInformation();
newView.Title = currentUserName;
//Show events that a re "created by"(Author) thisPerson["loggedInUser"]
newView.Query = "<Where><Eq><FieldRef Name='Author' /><Value Type='User'>" + loggedInUserName + "</Value></Eq></Where>";
calList.Views.Add(newView);
clientContext.ExecuteQuery();
}
}
else
{
//I don't think I need this but I post it just to show that its still not working even though I try to update the views.
Microsoft.SharePoint.Client.ViewCollection viewCollection = web.Lists.GetByTitle("CompanyCalendar").Views;
clientContext.Load(viewCollection);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.View view in viewCollection)
{
view.Update();
clientContext.ExecuteQuery();
}
testLabel.Text = "List already excist";
}
}
.
これは、ログインしたイベントを "developer"として追加した後( "Bergsten" -Viewの内部のユーザー名です)。
私の質問: このビューでは、追加しているイベントが表示されないのはなぜですか?彼らはデフォルトでカレンダービューで表示されますが、この "bergsten"を表示します。 CAMLフィルタリングは機能しないようです。私が行方不明になっているのか、それは私のView.Queryに何か問題なのですか?
解決
このようにしてみてください:
var loggedInUserName = thisPerson["loggedInUser"] as Microsoft.SharePoint.Client.FieldLookupValue;
int userId = loggedInUserName.LookupId;
//Create a new CalendarView
ViewCreationInformation newView = new ViewCreationInformation();
//Show events that are "created by"(Author) thisPerson["loggedInUser"]
newView.Query = "<Where><Eq><FieldRef Name='Author' LookupId='TRUE' /><Value Type='Lookup'>" + userId + "</Value></Eq></Where>";
.
これは仕事が必要です。
所属していません sharepoint.stackexchange