2016-09-07 64 views
0

如何使用Javascript在SharePoint日曆列表中設置RecurrenceData值?如何使用Javascript在SharePoint日曆列表中設置RecurrenceData值

var recurreciveData = "<recurrence> 
          <rule> 
           <repeat> 
            <daily dayFrequency=\"" + repeatDayz + "\" /> 
           </repeat> 
           <windowStart> 
            " + repeatStrtDate.toISOString() + " 
           </windowStart> 
           <windowEnd> 
            " + repeatEndDate.toISOString() + " 
           </windowEnd> 
          </rule></recurrence>"; 
var data = JSON.stringify({ 
    "__metadata": { 
     "type": "SP.Data."+ listName +"ListItem" 
    }, 
    "Title": title, 
    "Location": location, 
    "RoomId": room, 
    "EventDate": strtDate, 
    "EndDate": endDate, 
    "fRecurrence": true, 
    "RecurrenceData": recurreciveData, 
}); 

回答

1

對於通過SharePoint REST API以下屬性創建重複事件需要指定:

  • EventDate
  • EndDate
  • fRecurrence集到true
  • EventType集到1
  • RecurrenceData

var listTitle = "Calendar"; 
var itemProperties = { 
    '__metadata': { "type": "SP.Data.CalendarListItem" }, 
    'Title': 'Event 123', 
    'EventDate' : '2015-06-03T09:00:00Z', 
    'EndDate' : '2017-06-03T09:00:00Z', 
    'fRecurrence': true, 
    'EventType' : 1, 
    'RecurrenceData': '<recurrence><rule><firstDayOfWeek>su</firstDayOfWeek><repeat><daily dayFrequency="1" /></repeat><repeatForever>FALSE</repeatForever></rule></recurrence>' 
}; 

createListItem(listTitle,itemProperties) 
.done(function(item) 
{ 
    console.log('Event has been created'); 
}) 
.fail(function(error){ 
    console.log(JSON.stringify(error)); 
}); 

其中

function executeJson(options) 
{ 
    var headers = options.headers || {}; 
    var method = options.method || "GET"; 
    headers["Accept"] = "application/json;odata=verbose"; 
    if(options.method == "POST") { 
     headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val(); 
    } 

    var ajaxOptions = 
    {  
     url: options.url, 
     type: method, 
     contentType: "application/json;odata=verbose", 
     headers: headers 
    }; 
    if("data" in options) { 
     ajaxOptions.data = JSON.stringify(options.data); 
    } 

    return $.ajax(ajaxOptions); 
} 



function createListItem(listTitle,payload){ 
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items"; 
    return executeJson({ 
     "url" :url, 
     "method": 'POST', 
     "data": payload}); 
} 
+0

瓦迪姆嗨!謝謝!更改爲JSOM,效果很好,但在「日曆」視圖中打開時出現問題:https://sharepoint.stackexchange.com/questions/215859/jsom-calendar-recurring-task-item-does-not-exist-it-may -have-been-deleted-by你沒有這個問題嗎? –

相關問題