Pourquoi mon calendrier ne montre-t-il pas d'événements ajoutés - Quelque chose ne va pas avec mon caml?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/101610

Question

Mon code est assez simple. Je crée une liste de calendrier et des vues pour le calendrier.

Je crée une vue pour chaque contact dans ma liste de contacts personnalisés (contenant un champ "utilisateur" contenant le nom d'utilisateur de la connexion de cette personne).

Tout cela est créé lorsque je démarre mon APPLIATEUR ORGANISÉE AUX FOURNISSEURS .

La chose est que lorsque j'ajoute un événement de calendrier, je devrais pouvoir voir cet événement à mon avis. Dans mon champ utilisateur de calendrier personnalisé, j'ai ajouté mon nom d'utilisateur "développeur" dans mon cas. (Voir la photo)

Entrez la description de l'image ici

     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";
            }
        }

Ceci montre après que j'ajoute un événement connecté en tant que "développeur" (qui est le nom d'utilisateur à l'intérieur "Bergsten" -View).

Entrez l'image Description ici

ma question: Pourquoi ce point de vue ne montrait-il pas les événements que j'ajoute? Ils manifestent en défaut la vue du calendrier mais pas cette "Bergsten" -View. Le filtrage CAML ne semble pas fonctionner. Y a-t-il quelque chose qui me manque ou est-ce quelque chose de mal avec ma vue.Query?

Était-ce utile?

La solution

Pouvez-vous essayer comme ceci:

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>";

Cela devrait fonctionner ..

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top