Pnpjs: Calendar Recurring Events not expanding.

Created on 18 Apr 2019  路  7Comments  路  Source: pnp/pnpjs

Category

  • [x] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

1.3.2
Please specify what version of the library you are using: [ 1.3.2 ]

Please specify what version(s) of SharePoint you are targeting: [ SharePoint Online ]

Expected / Desired Behavior / Question

I am trying to get Events from Calendar along with Recurring Events using getItemsByCAMLQuery with QueryOptions. It is returning Parent Recurring Event but not expanidng it. If the event marked as Daily, expecting to show events data for daily. Is it an issue or I am any doing anything wrong?

Below is my code
const xml = <View> \ <ViewFields> \ <FieldRef Name=Title/> \ <FieldRef Name=EventDate/> \ <FieldRef Name=EndDate/> \ <FieldRef Name=Location/> \ <FieldRef Name=Description/> \ <FieldRef Name=fRecurrence/> \ <FieldRef Name=RecurrenceData/> \ <FieldRef Name=fAllDayEvent/> \ <FieldRef Name=ID/> \ </ViewFields> \ <Query> \ <Where> \ <DateRangesOverlap> \ <FieldRef Name=EventDate/> \ <FieldRef Name=EndDate/> \ <FieldRef Name=RecurrenceID/> \ <Value Type=DateTime> \ <Today /> \ </Value> \ </DateRangesOverlap> \ </Where> \ <OrderBy> \ <FieldRef Name=EventDate/> \ </OrderBy>\ </Query> \ <QueryOptions> \ <CalendarDate> + new Date().toISOString() + </CalendarDate>\ <ExpandRecurrence>TRUE</ExpandRecurrence>\ <RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>\ <RecurrenceOrderBy>TRUE</RecurrenceOrderBy>\ <ViewAttributes Scope=RecursiveAll/>\ </QueryOptions>\ <RowLimit>10</RowLimit> \ </View>;
let q: pnp.CamlQuery = {
ViewXml: xml,

};


pnp.sp.web.lists.getByTitle(LIST_NAME).items.filter(dateFilter).get().then(
  res=>{
    console.log('Direct Method..');
    console.log(res);
  }
);
non-library contribution opportunity馃悋 question

Most helpful comment

UPD: By default renderListDataAsStream does it. So start with renderListDataAsStream and find the corresponding caml or override which works for the usecase.

sp.web.lists.getByTitle('Calendar').renderListDataAsStream({}).then(console.log);

My assumption on OverrideViewXml in the previous sample was a false positive.

All 7 comments

You also need to have this in the Query Options in the CAML:
<ExpandRecurrence>TRUE</ExpandRecurrence>
See my post Retrieving Expanded Calendar Events with REST vs. SOAP

You also need to have this in the Query Options in the CAML:
<ExpandRecurrence>TRUE</ExpandRecurrence>
See my post Retrieving Expanded Calendar Events with REST vs. SOAP

Hi Sympmarc

Thanks for your reply. I have added ExpandRecurrence in the QueryOptions but still it is not expanding. And I came across your post even before also. I am not using SpServices library and looking for options in Sp-Pnp-Js. As your post was belong to July 2015, thought there will be some update.

Recurrent events is the pain in API, no support in OData. If getItemsByCAMLQuery doesn't work, you can try renderListData and renderListDataAsStream, e.g.:

import { sp } from '@pnp/sp';

sp.web.lists.getByTitle('Calendar')
    .renderListDataAsStream({
        OverrideViewXml: `
            <QueryOptions>
                <ExpandRecurrence>TRUE</ExpandRecurrence>
            </QueryOptions>
        `
    })
    .then(console.log)
    .catch(console.log);

image

UPD: By default renderListDataAsStream does it. So start with renderListDataAsStream and find the corresponding caml or override which works for the usecase.

sp.web.lists.getByTitle('Calendar').renderListDataAsStream({}).then(console.log);

My assumption on OverrideViewXml in the previous sample was a false positive.

UPD: By default renderListDataAsStream does it. So start with renderListDataAsStream and find the corresponding caml or override which works for the usecase.

sp.web.lists.getByTitle('Calendar').renderListDataAsStream({}).then(console.log);

My assumption on OverrideViewXml in the previous sample was a false positive.
Hi koltyakov,

Thanks for the reply.
My use case is to retrieve the Upcoming events from the calendar with pagination.

Below are my findings..

  1. for renderListDataAsStream() method, ExpandRecurrence is not needed as it is expanding it by default.
  2. RowLimit option in mentioned in the view xml, didn't have any impact. Sample below

const xml = <View> \ <Query> \ <Where> \ <DateRangesOverlap> \ <FieldRef Name=EventDate/> \ <FieldRef Name=EndDate/> \ <FieldRef Name=RecurrenceID/> \ <Value Type=DateTime> \ <Today /> \ </Value> \ </DateRangesOverlap> \ </Where> \ <OrderBy> \ <FieldRef Name=EventDate/> \ </OrderBy>\ </Query> \ <RowLimit>10</RowLimit> \ </View>;

  1. For Paging, we need to pass the Paging value.

sp.web.lists.getByTitle(LIST_NAME).renderListDataAsStream({OverrideViewXml: xml, Paging:'Paged=TRUE&RowLimit=5'}).then(
res=> { console.log(res); })

  1. But facing problem when trying to get 2nd Page. As per the document, to get the second page, we need to pass Last Id, and Last Title from the first page. In case of Recurring events, ID return was "2.0.2019-04-19T10:30:00Z" (It is there in your screen shot also). If we pass this value, getting empty rows.
    sp.web.lists.getByTitle(LIST_NAME).renderListDataAsStream({OverrideViewXml: xml, Paging:'Paged=TRUE&RowLimit=5'}).then(
    res=> { console.log(res);
    const lstId = res.Row[res.Row.length-1].ID;
    const lstTitle = res.Row[res.Row.length-1].Title;
    console.log(lstId);
    console.log(lstTitle);
    //Getting Second Page data
    sp.web.lists.getByTitle(LIST_NAME).renderListDataAsStream({OverrideViewXml: xml, Paging:'Paged=TRUE&RowLimit=5&p_ID=${lstId}&p_Title=${lstTitle}'}).then(
    res1=> { console.log(res1);
    });
    });

Looking for work around. If I find anything update here..

Going to close this as it doesn't appear to be an issue with the library. If there is still an issue here I missed please open a new issue and reference this one explaining what is not working and we can take a look. Thanks!

UPD: By default renderListDataAsStream does it. So start with renderListDataAsStream and find the corresponding caml or override which works for the usecase.

sp.web.lists.getByTitle('Calendar').renderListDataAsStream({}).then(console.log);

My assumption on OverrideViewXml in the previous sample was a false positive.

How can I selecct the column..i used this but not able to find the Category column in it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcosta33 picture jcosta33  路  3Comments

simkessy picture simkessy  路  3Comments

DennisGaida picture DennisGaida  路  3Comments

ITAndy23 picture ITAndy23  路  3Comments

SpliceVW picture SpliceVW  路  3Comments