BPC-Components

Home > Products > BPC PowerForms > Knowledge Base > API Reference > Helper Methods

Helper Methods

PowerForms helper methods is a collection of methods used to help with the creation of scripts.

 

pf.ParseDate

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:

Code

var dateInStringFormat = form.GetControl("c_RegistrationDate").GetValue();

var registrationDateObject = pf.ParseDate(dateInStringFormat);

var theRegistrationYear = registrationDateObject.getFullYear();

alert(theRegistrationYear);

 

pf.IsEmpty

The above method checks an object to see if it is null or empty.

Example:

Code

if(pf.IsEmpty(value))

{

      alert("Empty value object");

}

 

pf.GetNameFromLookup and pf.GetValueFromLookup

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:

Code

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:

Code

pf.GetNameFromLookup(form.DataItem.Author)

returns Sharepoint Administrator.

 

To retrieve only the Value part:

Code

pf.GetValueFromLookup(form.DataItem.Author)

returns 1.

 

pf.GetNamesFromMultiLookup and  pf.GetValuesFromMultiLookup

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:

Code

pf.GetNamesFromMultiLookup(items[i].CompanyType, ", ")

returns USA,Middle East and Europe,North Asia.

 

To retrieve only the Value part:

Code

pf.GetValuesFromMultiLookup(items[i].CompanyType, ",")

returns 1,3,2.

 

pf.Format(obj, format, locale) 

This function can be used to format a Number or Date using the specified format and the current culture.

 Examples:

Code

pf.Format(new Date(2013, 3, 12, 22, 12), "dddd MMMM d, yyyy hh:mm tt", "en-US");

 

 

pf.SetCookie(c_name, value, exdays) 

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:

Code

pf.SetCookie("test","test123", "1");

 

 

pf.GetCookie(c_name) 

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:

Code

var theCookieValue = pf.GetCookie("test");

alert(theCookieValue); 

 

 

pf.AddDaysToDate(date, number of days to add) 

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:

Code

var theNewDateValue= pf.AddDaysToDate(new Date(), 2);

alert(theNewDateValue); 

 


pf.AddDaysToDateSting(string date, number of days to add) 

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:

Code

var theDateValue = form.GetControl('c_Date').GetValue(); 

var theNewDateValue = pf.AddDaysToDateString(theDateValue, 2);

alert(theNewDateValue ); 

 

 

pf.CloneObjectSimpleProperties(object) 

This function clones only a control's simple properties. It is mainly used for serialization.

 Examples:

Code

 

var rr = pf.CloneObjectSimpleProperties(form.GetControl("c_Control1").InputControl);
alert(pf.ObjectProperties(rr));