I have to tick ‘All Day Event’ check box for SharePoint Calendar Event input form.
So add below code into new form


$(document).ready(function () {

var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
});

At the beginning it works fine but when I un-tick the check box again, it reload the form again and then the script loaded again so there is no way to un-tick the check box.
So I need to check whether this form is from postback or not but I can’t find any internal SharePoint javascript variable or function to check postback.

So the only way is check document.referrer and document.location.href.


$(document).ready(function () {
if( document.referrer != document.location.href )
{
var $checkBoxAllDayEvent = $("span[title='All Day Event']> input");
if( $checkBoxAllDayEvent.length > 0){

//instead setting the box checked, better to call the click event
if( !$checkBoxAllDayEvent.attr("checked") ){
$checkBoxAllDayEvent.click();
}
}
}
});

Advertisements

Method 1)

/**
* @class ObjItem
* @type {Object}
* @property {id}
* @property {title}
* @property {startDay}
* @property {category}
*/
function ObjItem(id, title, startDay, category){
this.id = id;
this.title = title;
this.startDay = startDay;
this.category = category;
}


var myItem = new ObjItem(1, "Test Title", "2017-10-04", "Holiday");

Method 2)

/**
* @class ObjItem
* @type {Object}
* @property {id}
* @property {title}
* @property {startDay}
* @property {category}
*/
function makeObjItem(id, title, startDay, category){
var obj = {
id: id,
title: title,
startDay: startDay,
category: category
};
return obj;
}


var myItem = makeObjItem(1, "Test Title", "2017-10-04", "Holiday");

Reference from :
https://stackoverflow.com/questions/12272239/javascript-function-returning-an-object
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

I normally use “Items” for SharePoint Rest query but with Calendar some issues.

var requestUri = _spPageContextInfo.webAbsoluteUrl
+”/_api/Web/lists/getbytitle(‘” + glbCalendarDisplayName + “‘)/Items”
+ “?” + querySelectOption
+ “&” + querySortingOption
+ “&” + queryExpandOption
+ “&” + queryFilterOption
+ “&” + queryPagingOption

* Have to use GET type

Filter with EventDate/EndDate not allowed.

  • Error : “The field ‘EventDate’ of type ‘DateTime’ cannot be used in the query filter expression.”
  • But if I add new date type field into the Calendar and filter with the date field it works fine.

* Error for filtering with SharePoint Calendar OOTB date field EventDate/EndDate
var queryFilterOption = “$filter=EventDate le datetime'”+endDateString
+ “‘ and EndDate ge datetime'”+startDateString+”‘”;

* No error for filtering with new added date field
var queryFilterOption = “$filter=NewAddedFieldDate le datetime'”+endDateString+”‘”;

So how about let’s use Calm Query into other Rest endpoint GetItems

var requestUri = _spPageContextInfo.webAbsoluteUrl
+ “/_api/Web/lists/getbytitle(‘”+glbCalendarDisplayName+”‘)/GetItems(query=@v1)”
+ “?” + querySelectOption
+ “&” + queryPagingOption
//+ “&” + queryExpandOption  //expand not working.
//+ “&” + querySortingOption //sorting not working.
+ “&@v1=” + JSON.stringify(viewXml)

* Have to use POST type

* in the headers need “X-RequestDigest”: jQuery(“#__REQUESTDIGEST”).val()

First the Calm query applied and then other parameter passing option applied.

Disadvantage for GetItems :

  1. can’t use expand such as Author.
  2. Returned date/time type is without UTC designator(“Z”) so it’s local time format with site settings/reginonal settings.
    • ISO 8601 UTC designator format : “2017-08-31T16:00:00Z”
    • ISO 8601 without time zone offset : “2017-09-01T00:00:00”
  3. So in the CAML query when you filter the date should use ISO8601 without time zone offset to get accurate data. (this is only for GetItems tricky solution. in case of Items you can use with ~Z type.)

var startDateString = “2017-09-01T00:00:00.000”; //’2017-08-31T16:00:00.000Z’ will get unwanted result

var endDateString = “2017-09-30T23:59:59.999″; //’2017-09-30T15:59:59.999Z’ will get unwanted result

var viewXml = {var viewXml = {ViewXml:”<View>” +”<Query>” +//”<OrderBy><FieldRef Name=’EventDate’ Ascending=’True’ />” + “</OrderBy>” +”<Where><And>” +”<Geq>” +”<FieldRef Name=’EndDate’ /><Value Type=’DateTime’ IncludeTimeValue=’TRUE’>” + startDateString + “</Value>” +”</Geq>” +”<Leq>” +”<FieldRef Name=’EventDate’ /><Value Type=’DateTime’ IncludeTimeValue=’TRUE’>” + endDateString +”</Value>” +”</Leq>” +”</And></Where>” +”</Query>” +”<RowLimit>” + viewPageSize + “</RowLimit>” +/*”<ViewFields>” +”<FieldRef Name=’AuthorId’ />” +”<FieldRef Name=’Title’ />” +”<FieldRef Name=’Category’ />” +”<FieldRef Name=’EventDate’ />” +”<FieldRef Name=’EndDate’ />” +”<FieldRef Name=’fRecurrence’ />” +”<FieldRef Name=’fAllDayEvent’ />” +”<FieldRef Name=’EventType’ />” +”<FieldRef Name=’RecurrenceData’ />” +”<FieldRef Name=’MasterSeriesItemID’ />” +”<FieldRef Name=’Duration’ />” +”<FieldRef Name=’RecurrenceID’ />” +”<FieldRef Name=’TimeZone’ />” +”<FieldRef Name=’UID’ />” +”<FieldRef Name=’XMLTZone’ />” +”</ViewFields>” +*/”</View>”};

Recurrence information select

by default the recurrence information is not select so have to define the select option manually.

var querySelectOption = “$select=Title,EventDate, EndDate, AuthorId,RecurrenceData,MasterSeriesItemID,EventType,Duration,RecurrenceID,TimeZone,UID,XMLTZone”;

EventRecurrenceInformation

 

 

 

There is 2010 style web service call as well to filter the event date.

But the field name should be StartTime and EndTime

var queryFilterOption = "$filter=StartTime le datetime'"+endDateString
+ "' and EndTime ge datetime'"+startDateString+"'";
var requestUri = _spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/"+ glbCalendarDisplayName
+ "?" + querySelectOption
+ "&" + queryFilterOption

disadvantage :

  1.  can’t select recurrence data.
  2. the returned date is millisecond format so have to convert and have to apply timezone offset
    • for example : “/Date(1506384000000)/”
    • new Date(parseInt(RESTReturn[i].StartTime.match(/\/Date\(([0-9]+)(?:.*)\)\//)[1]) – 8*60*60*1000)

 

References)

https://fatalfrenchy.wordpress.com/2010/07/16/sharepoint-recurrence-data-schema/

https://github.com/SharePoint/PnP/tree/master/Samples/Core.DisplayCalendarEvents

http://www.hubfly.com/blog/solutions/how-to-get-sharepoint-event-recurrence-data-using-rest-api/

http://itblog.wolthaus.net/2011/12/rest-filter-datetime/

https://kartooz.wordpress.com/2009/02/20/querying-sharepoint-calendar-for-recurring-events-using-caml-query/

https://sharepoint.stackexchange.com/questions/146085/submitting-recurrence-data-with-spservice

https://social.msdn.microsoft.com/Forums/office/en-US/5e63a4e9-5b62-402d-beaf-57bb98a376d7/recurrence-events-via-rest?forum=sharepointcustomization

https://social.technet.microsoft.com/Forums/en-US/d4e87de2-4ad1-4b7c-9bbc-891ec10bf4d9/handling-recurring-events-using-sharepoint-2013-rest-api?forum=sharepointdevelopment

https://social.technet.microsoft.com/wiki/contents/articles/32133.sharepoint-2013-retrieve-recurrence-data-programmatically-from-a-calendar-list.aspx

https://sharepoint.stackexchange.com/questions/136482/sharepoint-rest-api-using-caml-query-and-select-expand-to-get-lookup-data

SharePoint REST API: Retrieve List Items Comparison

SharePoint REST API: Retrieve List Items Comparison

https://threewill.com/using-the-expand-odata-query-option-in-sharepoint-2013/

https://msdn.microsoft.com/en-us/library/office/dn531433.aspx#bk_ListItemCollectionEndpoint

https://social.msdn.microsoft.com/Forums/office/en-US/e9952029-a1b1-4560-ac94-f27b67af1aed/sharepoint-app-rest-api-expand-not-working-with-getitems?forum=appsforsharepoint

 

 

 

My scenario : get the date format value from http web service call.

The date/time format is ISO format such as “2017-08-10T17:36:12Z”

Actual local time(Perth) is 11/08/2017 1:36:12.

However when I tried to save the field value as Date/Time workflow variable, exception happens like below error message.

The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local

Without the last character ‘Z’ is working to conversion and set the date/time variable.

  • Copy from [StrOriginalISOFormatWithZ], starting at 0 for 19 characters(Output to [StrTempISOFormatWithoutZ])
    • [StrOriginalISOFormatWithZ] : 2017-08-10T17:36:12Z
    • [StrTempISOFormatWithoutZ] : 2017-08-10T17:36:12
  • Set [DateTimeTmpVariable] to [StrTempISOFormatWithouZ]
    • [DateTimeTmpVariable] : 2017-08-10T09:36:12Z
  • Add 0 months, 0 days, 8 hours, 0 minutes to [DateTimeTmpVariable](Output to [DateTimeFinalVariable])
    • [DateTimeFinalVariable] : 2017-08-10T17:36:12Z

 

Date/Time Output format example

  • As String           : 11/08/2017 1:36:12 AM
  • ISO Formatted : 2017-08-10T17:36:12Z
  • Long Date  : Friday, 11 August 2017
  • Long Time : 1:36:12 AM
  • ShortDate  : 11/08/2017
  • ShortTime : 1:36 AM

 

Get Time Zone information for SharePoint site. (get Bias value)

[SharePointSiteURL]/_api/web/RegionalSettings/TimeZone

d/Information/Bias

{
“d”: {
“__metadata”: {
“id”: “[SharePointSiteURL]/_api/web/RegionalSettings/TimeZone”,
“uri”: “[SharePointSiteURL]/_api/web/RegionalSettings/TimeZone”,
“type”: “SP.TimeZone”
},
“Description”: “(UTC+08:00) Perth”,
“Id”: 73,
“Information”: {
“__metadata”: {
“type”: “SP.TimeZoneInformation”
},
“Bias”: -480,
“DaylightBias”: -60,
“StandardBias”: 0
}
}
}

Reference:

http://www.c-sharpcorner.com/UploadFile/58e23e/call-http-web-service-using-sharepoint-designer-2013-spd/

https://code.msdn.microsoft.com/officeapps/sharepoint-2013-accessing-a90295d2

https://dev.office.com/sharepoint/docs/general-development/working-with-web-services-in-sharepoint-workflows-using-sharepoint-designer

 

*Sometimes you get unauthorized error from rest query.

just add “Authorization” with no value into request header dictionary.

https://sharepoint.stackexchange.com/questions/118876/call-http-web-service-unauthorized

*ISO formatted value is not saved into workflow date/time variable.-> so have to remove ‘Z’ character from string value and then save into workflow variable. adjust time variance using add time calculator function in SharePoint Designer.

*Check the date is Monday-> check the variable(Short Date) include ‘Monday’ Character

 

Get document name/page name

https://social.msdn.microsoft.com/Forums/Lync/en-US/a9db1de8-a182-455a-88fa-af918c6e22c1/get-document-name-from-2013-workflow?forum=sharepointcustomization

https://weblogs.asp.net/ricardoperes/looping-through-list-items-in-sharepoint-2013

Get FileRef value

select FileRef

Order by, Filter by datetime and paging

$orderby=DueDate desc

$filter=DueDate gt DateTime’2014-07-31T00:00:00’

$top=20

Get current time for SharePoint 2013 workflow.

http://myknowlex.blogspot.com.au/2016/01/sharepoint-2013-online-workflow-get.html

 

Sharepoint designer workflow string limit : 255 character (history log as well)

Sharepoint Workflow throttling : 5000 outbound request/24 hour period.

https://support.microsoft.com/en-us/help/3076399/sharepoint-2013-workflow-throttling-and-performance-in-sharepoint-onli

 

 

https://weblogs.asp.net/ricardoperes/getting-the-weather-forecast-using-sharepoint-workflows

 

Have to check the url exceed 255 character 

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

/items/?$select=*,FileRef,Author/Title,Editor/Title,File/Name&$expand=Author,Editor,File&$orderby=Modified desc&$filter=Modified ge datetime’2017-08-21T16:00:00Z’

/items/?$select=ID,Title,FileRef,Modified,Created,Author/Title,Editor/Title,File/Name&$expand=Author,Editor,File&$filter=Modified ge datetime’2017-08-21T16:00:00Z’

 

 

 

 

When I tried to get lookup item’s other field using rest query I got this error message

The query to field ‘LookupFieldName/ParentFieldName’ is not valid.

However LookupFieldName/ID, LookupFieldName/Title, LookupFieldName/Created works fine.

Seems only get the value following field types only.

  • Number
  • Single line or text
  • Date and Time