PowerForms helper methods is a collection of methods used to help with the creation of scripts.
The above method can be used to easily create a Date object. Date objects can then be used to retrieve year, month and day. DatePicker control values are simple strings. ParseDate can be used to turn DatePicker values to date objects with ease.
For example, c_RegistrationDate is a DatePicker control. To retrieve the registration year, one must do the following:
var dateInStringFormat = form.GetControl("c_RegistrationDate").GetValue();
var registrationDateObject = pf.ParseDate(dateInStringFormat);
var theRegistrationYear = registrationDateObject.getFullYear();
alert(theRegistrationYear);
The above method checks an object to see if it is null or empty.
Example:
if(pf.IsEmpty(value))
{
alert("Empty value object");
}
The above two functions can be used with any lookup value of the type value;#name.
i.e. 1;#Administrator, 15;#Company.
Values of the above type can be extracted from PeoplePicker, LookupPicker, RadioButton or Combobox controls.
For our examples, we will retrieve the author of a list item using the following formula:
form.DataItem.Author
The above statement returns the following value:
1;#Sharepoint Administrator, which is of the value;#name type.
To retrieve only the Name part:
pf.GetNameFromLookup(form.DataItem.Author)
returns Sharepoint Administrator.
To retrieve only the Value part:
pf.GetValueFromLookup(form.DataItem.Author)
returns 1.
The above two functions can be used with any multilookup value of the type value1;#name1;#value2;#name2;#value3;#name3.
i.e. 1;#USA;#3;#Middle East and Europe;#2;#North Asia.
Both functions require two parameters to function, the actual values and a seperator, i.e. a comma (,)
pf.GetNamesFromMultiLookup(values, seperator)
pf.GetValuesFromMultiLookup(values, seperator)
To retrieve only the Name part:
pf.GetNamesFromMultiLookup(items[i].CompanyType, ", ")
returns USA,Middle East and Europe,North Asia.
To retrieve only the Value part:
pf.GetValuesFromMultiLookup(items[i].CompanyType, ",")
returns 1,3,2.
This function can be used to format a Number or Date using the specified format and the current culture.
Examples:
pf.Format(new Date(2013, 3, 12, 22, 12), "dddd MMMM d, yyyy hh:mm tt", "en-US");
This function can be used to create a cookie for the current page. The function accepts three variables, the name of the cookie, the actual cookie value and the number of days till the cookie expires.
Examples:
pf.SetCookie("test","test123", "1");
This function can be used to retrieve the value of a previously created cookie. The function accepts one variable, the name of the cookie.
Examples:
var theCookieValue = pf.GetCookie("test");
alert(theCookieValue);
This function can be used to add number of days in a date variable. The function accepts two arguments, the value of the date and the number of days that is going to be added.
Examples:
var theNewDateValue= pf.AddDaysToDate(new Date(), 2);
alert(theNewDateValue);
This function can be used to add number of days in a date string variable. The function accepts two arguments, the string value of the date and the number of days that is going to be added.
Examples:
var theDateValue = form.GetControl('c_Date').GetValue();
var theNewDateValue = pf.AddDaysToDateString(theDateValue, 2);
alert(theNewDateValue );
This function clones only a control's simple properties. It is mainly used for serialization.
Examples: