, ,

The HyperlinkTextBox control

The Hyperlink TextBox targets SharePoint columns that store hyperlinks or picture urls.

In contains 2 textboxes. One for the actual URL and one for its description (the same way it appears in the default SharePoint forms). If no description is provided by users, the url is used for the description part.

Type : HyperlinkTextBox

Name

Provides a unique name for the control.

Binding

Indicates if the control is

  • Unbound
  • Bound to list column
  • Is a label for a control bound to list column

Enabled for new records

Sets if the control will be enabled or disabled when the forms handles a new record

Enabled for existing records

Sets if the control will be enabled or disabled when the forms handles an existing record

Required

Marks the cotnrol as Required.

By default, the system recognizes required fields and marks them with this flag. Additionaly, controls can be marked as required event if the bound column is not.

Enabled Formula

Set an expression then will be evaluated during run-time and enable or disable the control.

The expression must be in javascript and should return a boolean value.

Dependencies between controls are automatically identified and the expression is re-calculated every time a control affecting the formula changes.

Example :

Code

form.GetControl(“c_Status”).GetValue() != “Open” && form.UserInGroup(“Administrators”)

Visibility Formula

Define a valid formula (using javascript) that will be evaluated during runtime to show or hide the control.

The expression should return a boolean value.

For example :

Code

form.FieldValue(“c_Status”) != “Rejected” || form.UserID() == “1”

Value

This property defines how the control will get its value.

 

Here are the available options :

  1. The value is Static (this is the default for label controls)
  2. The value will be provided by the user (Not applicable for labels)
  3. The value will be calculated by a formula
  4. The value will be retrieved from a list query
  5. The value will be provided by a web service call
  6. The value will be provided by a SQL query
Static value

A static text must be set in the appropriate designer control.

Formula

A javascript expression must be set that will provide the value for the control.

If the formula contains references to other controls, dependencies will be automatically identifies during run-time and the value will be updated to reflect changes.

Example :

Code

form.FieldValue(“c_Active”) ? “Yes” : “No”

There is an additional option that instructs the form to perform calculations only for new records. Existing records will keep their original value.

List Query

A predefined list query is bound to the value of the control. So during form initialization, the specified list query is executed and if it returns any item, it selects the first one and it will apply the value to the label based on the following rule :

If a Field Name has been selected in the corresponding box, that specific column will be used from the list item to fill the control value.

If the Field Name is left blank, the first column retrieved will be used.

Web Service

The same as above, the required web service is selected and after the web service retrieves data, the first item will be used to update the control value. If no Field Name is set, the control will receive the first field of the  retrieved item.

SQL Query

Works the same way ListQueries and Web Service works.

Default Value

The default value has any effect only of the control is bound to a list column.

For unbound controls, the default value is ignored.

You may set a static value here or use a formula by starting your input with the “equals” (=) sign.

Example :

Code

=”User : ” + form.UserFullName()

Width

Not Applicable for the HyperlinkTextBox control.

Height

Not Applicable for the HyperlinkTextBox control.

H.Alignment

Defines the horizontal alignment of the parent cell (values : left, right, center)

V.Alignment

Defines the vertical alignment of the parent cell (values : top, bottom, center)

Fore Color

Not Applicable for the HyperlinkTextBox control.

Back Color

Not Applicable for the HyperlinkTextBox control.

Cell Color

Defines the color of the parent cell.

Font Size

Declares the font size of the text

Margin

Sets the margin applied to the control, that is, the spacing between the control and the cell borders.

Font Bold

Changes the weight of the font used

Italics

Changes the font style for the control text

Not Applicable for this control

ShowDescription

Shows or hides the description part of the control.

Sets the script that will be executed at the value-change event of the control.

Example :

Code

var value = form.GetControl(“c_Title”).GetValue();

if (value == “Open”) form.HideSection(“Details”);

else form.ShowSection(“Details”);

 

, ,

The Hyperlink control

The Hyperlink control targets Sharepoint columns that store hyperlinks or picture urls.

Type : Hyperlink

Name

Provides a unique name for the control.

Binding

Indicates if the control is

  • Unbound
  • Bound to list column
  • Is a label for a control bound to list column

Enabled for new records

Sets if the control will be enabled or disabled when the forms handles a new record

Enabled for existing records

Sets if the control will be enabled or disabled when the forms handles an existing record

Required

Marks the cotnrol as Required.

By default, the system recognizes required fields and marks them with this flag. Additionaly, controls can be marked as required event if the bound column is not.

Enabled Formula

Set an expression then will be evaluated during run-time and enable or disable the control.

The expression must be in javascript and should return a boolean value.

Dependencies between controls are automatically identified and the expression is re-calculated every time a control affecting the formula changes.

Example :

Code

form.GetControl(“c_Status”).GetValue() != “Open” && form.UserInGroup(“Administrators”)

Visibility Formula

Define a valid formula (using javascript) that will be evaluated during runtime to show or hide the control.

The expression should return a boolean value.

For example :

Code

form.FieldValue(“c_Status”) != “Rejected” || form.UserID() == “1”

Value

This property defines how the control will get its value.

 

Here are the available options :

  1. The value is Static (this is the default for label controls)
  2. The value will be provided by the user (Not applicable for labels)
  3. The value will be calculated by a formula
  4. The value will be retrieved from a list query
  5. The value will be provided by a web service call
  6. The value will be provided by a SQL query
Static value

A static text must be set in the appropriate designer control.

Formula

A javascript expression must be set that will provide the value for the control.

If the formula contains references to other controls, dependencies will be automatically identifies during run-time and the value will be updated to reflect changes.

Example :

Code

form.FieldValue(“c_Active”) ? “Yes” : “No”

There is an additional option that instructs the form to perform calculations only for new records. Existing records will keep their original value.

List Query

A predefined list query is bound to the value of the control. So during form initialization, the specified list query is executed and if it returns any item, it selects the first one and it will apply the value to the label based on the following rule :

If a Field Name has been selected in the corresponding box, that specific column will be used from the list item to fill the control value.

If the Field Name is left blank, the first column retrieved will be used.

Web Service

The same as above, the required web service is selected and after the web service retrieves data, the first item will be used to update the control value. If no Field Name is set, the control will receive the first field of the  retrieved item.

SQL Query

Works the same way ListQueries and Web Service works.

Default Value

The default value has any effect only of the control is bound to a list column.

For unbound controls, the default value is ignored.

You may set a static value here or use a formula by starting your input with the “equals” (=) sign.

Example :

Code

=”User : ” + form.UserFullName()

Width

Not Applicable for the Hyperlink control.

Height

Not Applicable for the Hyperlink control.

H.Alignment

Defines the horizontal alignment of the parent cell (values : left, right, center)

V.Alignment

Defines the vertical alignment of the parent cell (values : top, bottom, center)

Fore Color

Defines the fore color of the control

Back Color

Not Applicable for the Hyperlink control

Cell Color

Defines the color of the parent cell.

Font Size

Declares the font size of the text

Margin

Sets the margin applied to the control, that is, the spacing between the control and the cell borders.

Font Bold

Changes the weight of the font used

Italics

Changes the font style for the control text

Not Applicable for this control

Text

The hyperlink text. If left blank, the URL will be shown.

Target

The hyperlink target (i.e. _blank)

Actions

The actions to be executed once the button is clicked are defined here. The sequence of the execution follows the order of the actions definition. In order to add an Action entry in this collection, press the button. Each action has the following properties:

Type: Sets the type of the action to be executed. Available values:

  • Script: Javascript code to be executed. See “Form Properties and Methods” and “Controls Properties and Methods” article for a list of available functions and code samples.
  • SetValue: Provides a value (specified to the “Value” property) to the control specified in the “ControlName” property.
ControlName: Applicable only for SetValue actions.

Value: The script to be executed (in case of script actions) or the value to be set on the control (in case of SetValue actions). For SetValue actions, references to controls are allowed, for example {c_Title}.

The following example will display a message to the form once the button is clicked, and then set the title’s text to the c_Description control:

 

Sets the script that will be executed at the value-change event of the control.

Example :

Code

var value = form.GetControl(“c_Title”).GetValue();

if (value == “Open”) form.HideSection(“Details”);

else form.ShowSection(“Details”);

 

, ,

The DocumentGrid Control

The DocumentGrid control is a container for listing the documents in a SharePoint document library, and provides the means of opening, deleting or uploading a document from/to a specific location:

“Open” button will open the selected document, prompting for ReadOnly/Edit mode just like SharePoint does.

“Refresh” button will reload the grid’s data.

“Remove” button will delete the document from the library.

“Upload” button will add a new document from the user’s local disc (the new document is selected with the “Browse” button)

In order to specify the document library from which to retrieve the documents, a ListQuery must be defined and provided as a value to the control (see “Value” below).

 

Type : DocumentGrid

Name

Provides a unique name for the control.

Binding

Not Applicable for the DocumentGrid control. It is always unbound.

Enabled for new records

Sets if the control will be enabled or disabled when the forms handles a new record

Enabled for existing records

Sets if the control will be enabled or disabled when the forms handles an existing record

Note: When not enabled, the grid’s “Remove” and “Upload” buttons are disabled.

Required

Not Applicable for DocumentGrid control.

Enabled Formula

Set an expression then will be evaluated during run-time and enable or disable the control.

The expression must be in javascript and should return a boolean value.

Dependencies between controls are automatically identified and the expression is re-calculated every time a control affecting the formula changes.

Example :

Code

form.GetControl(“c_Status”).GetValue() != “Open” && form.UserInGroup(“Administrators”)

Note: When not enabled, the grid’s “Remove” and “Upload” buttons are disabled.

Visibility Formula

Define a valid formula (using javascript) that will be evaluated during runtime to show or hide the control.

The expression should return a boolean value.

For example :

Code

form.FieldValue(“c_Status”) != “Rejected” || form.UserID() == “1”

 

Value

The DocumentList control receives its value only with a ListQuery. A predefined list query that returns a set of list items each of which corresponds to a document in a library, is bound to the value of the control. Let’s assume the following List Query is defined in the respective section of the designer:

 

This ListQuery will be used to provide data to the DocumentGrid control:

Default Value

Not applicable for the DocumentGrid control.

Width

Defines the width of the control.

When the value is zero, the maximum allowed width will be used.

Height

Defines the control height.

If the value is zero, the height property will not be set.

H.Alignment

Defines the horizontal alignment of the parent cell (values : left, right, center)

V.Alignment

Defines the vertical alignment of the parent cell (values : top, bottom, center)

Fore Color

Not applicable for the DocumentGrid control.

Back Color

Not applicable for the DocumentGrid control.

Cell Color

Defines the color of the parent cell.

Font Size

Declares the font size of the text

Margin

Sets the margin applied to the control, that is, the spacing between the control and the cell borders.

Font Bold

Changes the weight of the font used

Italics

Changes the font style for the control text

 

Lookup Details

Not applicable for the DocumentGrid control. The control’s data are retrieved through ListQuery.

 

PageSize

Define the page size for the grid. Zero indicates no paging.

ShowGroups

This property enables or disables grouping for the grid data

TargetFolder

Define the folder where new attachments should be uploaded. If empty, it assumes the default root folder of the document library defined in the ListQuery.

AllowUpload

Enables/Disables Uploading

AllowDelete

Enables/Disables Delete

DataLoadedScript

Javascript code to be executed once the data inside the DataGrid are loaded. The reserved variable “items” contains the items retrieved. The following example will show the ID of the first item in the list:

Code

if (items.length > 0)

{
  alert(“The first item’s ID is: ” + items[0].ID);
}

 

 

SelectionChangedScript

Javascript code to be executed once the row selection changes. The “item” variable contains a reference to the selected list item. The following example outputs the ID and Title fields of the selected grid item.

Code

alert(“ID: ” + item.ID + ”  Title:” + item.Title);

 

 

LoadCompletedScript

Occurs AFTER the data have been placed inside the grid. The ‘items’ variable is available containing the items retrieved.

DaysToShowNewIndicator

Define the duration (in days) for which the new indicator will be shown in the Field(s) where ShowNewIndicator=true. The duration is compared with the Created Date (‘Created’ field) of the record.

 

NewIndicatorImageURL

Specify the url of the image to display as a ‘new’ indicator.

 

Values

Name/Value pairs that are goind to be used to update the document’s meta data when a new document is uploaded. This is extremely useful in master detail records, for example when a document library named “Order Documents” has a custom column named “OrderID” that links that document with a list named “Orders”. In this case, you would input a pair Name=OrderID, Value = {c_ID} (Value can take either static or calculated values based on existing fields).

 

Fields

The fields to be presented to the grid. If ommited, then the columns returned from the ListQuery are displayed. Each field has the following attribute:

Name:  The internal name of the column to display.

Header:  The column header.

Width: The grid column width (for example 200px). Leave blank for auto sizing.

DisplayFormat: Indicates the way the value will be presented inside the data grid. (The value as-is, the ValueField or DisplayField for lookup controls (ID;#TITLE), Date, DateTime, or Number).

FormatString :  Sets the format for Date and Number fields. For example ‘#,##0.00’ or ‘MM/dd/yyyy’.

ForeColor: The color of the cell’s text.

FontBold: Sets whether the text font will be bold or not.

FontSize: Sets the font size (for example 20px)

HAlign: Sets the Horizontal align of the column (Left, Center, Right)

ColumnFiltering :  If selected, then the grid displays a dropdown menu when the user clicks this column, for filtering and sorting purposes.

ShowNewIndicator :  If this property is set to True, the sharepoint ‘new’ indicator will be shown next to the column value.

Not applicable for Grid controls. Use SelectionChangedScript and DataLoadedScript.

 

 

ExportToExcel

As the name suggests, this function will export the data to an Excel file, ready to be saved or opened. The function accepts three parameters, described below:
ExportToExcel(array of columns, string file name, string sheet name) 
Columns should be an array of objects with “field” and “title” properties. If no columns are provided, all of the grid’s visible columns will be exported.
 Example:
Code
var grid = form.GetControl(“c_Cases”).InputControl.DataGrid;
var cols = [];
cols.push({field:”CaseNumber”, title:”Case Number”});
cols.push({field:”Title”, title:”Title”});
cols.push({field:”CaseType”, title:”Case Type”});
cols.push({field:”CType”, title:”Case Category”});
grid.ExportToExcel(cols, “Cases.xls”, “Cases”);

 

 

DocumentUploading

This event will fire as soon as you press the Upload button on the DocumentGrid control, just before the actual documents are uploaded.
Example:
Show a confirmation dialogue to the user, asking whether to upload the documents or not. If the user presses yes, the documents will be uploaded, otherwise they will not.
Code
var grid = form.GetControl(“c_aDocumentGrid”).InputControl;
grid.DocumentUploading.AddHandler(function (e2) {
    pf.UploadValues(e2);
});
pf.UploadValues = function(e) {
    var conf = confirm(“Are you sure you want to upload this file?”);
    // documents to be loaded
    alert(grid.CTRL_ADD_FILES.value);
    if(conf == true){
      // continues uploading files
      e.Cancel = false;
      e.Callback(e);
    }
    else
    {
      // cancels uploading
      e.Cancel = true;
    }
}

 

DocumentUploaded

This event will fire, after a document gets uploaded, using the DocumentGrid control.
Example:
Code
var grid = form.GetControl(“c_aDocumentGrid”).InputControl;
grid.DocumentUploaded.AddHandler(function (e3) {
     alert(“Document Uploaded!”);
});
, ,

Form Properties and Methods

Either inside formulas or when writing javascript to accomplish complex requirements, you can use the client-side API provided by PowerForms – HTML.

A global variable named “form” is available wherver you can use script :

  • In form events (Load, Validation, etc)
  • Inside Enabled and Visibility formulas
  • In control Value-Change events
  • In custom events provided by specific controls (like grids)

 

DataItem

Type : Object

Represents the record data. Each property of the object represents a list column.

The internal names of columns have been used to build this object.

MaintainTabSelection

Type : Bool

In case that the form contains more than one tab selections, after the save action, the last selected tab will maintain selected if it is set true.

Loaded

Type : Bool

This property is true while the form is loading and becomes false as soon as the user starts editing the data in the form.

The is useful when you want to change the value of controls during the Value-Change event of another control.

Since the Value-Change events are raised even when the form is initialized, that may have unwanted results.

For example :

You want every time the user selects a specific customer from a combobox, to automatically set the priority combo to “High”. This should act as a default value for that control, but the user may change it afterwards. So we apply this rule only when the value of the combo is changed by a user action.

Example:

Code

// Code inside the Value-Change event of the Customer combo

var customer = form.GetControl(“c_Customer”).GetValue_Name();

if (customer == “BPC”) form.GetControl(“c_Priority”).SetValue(“High”);

// The above code is incorrect, since it would also run during form initialization

// when the form applies values from the list item to controls.

// The correct way would be the following :

var customer = form.GetControl(“c_Customer”).GetValue_Name();

if (form.Loaded) {

  if (customer == “BPC”) form.GetControl(“c_Priority”).SetValue(“High”);

}

FieldValue(controlName)

Return type : string

Used to retrieve the current value of a control on the form.

The value is always retrieved as a string.

For date values, ANSI format is used.

For numeric values, US locale is used.

For lookup values, the ID;#TITLE format is used.

For boolean values, 1 or 0 is returned.

Example :

Code

form.FieldValue(“c_Title”);

Enabled formula example :

Code

form.FieldValue(“c_Status”) != “Open”

FieldValue_Name(controlName)

Return type : string

This method is used for lookup controls only and it returns the TITLE part of the control value (ID;#TITLE)

For example, a combobox lookup control has the value : 2;#Open

Code

var a = form.FieldValue(“c_Status”);

// returns “2;#Open”

var b = form.FieldValue_Name(“c_Status”);

// returns “Open”

FieldValue_Value(controlName)

Return type : string

This method is used for lookup controls only and it returns the ID part of the control value (ID;#TITLE)

For example, a combobox lookup control has the value : 2;#Open

Code

var a = form.FieldValue(“c_Status”);

// returns “2;#Open”

var b = form.FieldValue_Value(“c_Status”);

// returns “2”

FieldValues(controlName, separator)

Return type : string

This method is used for multi-lookup controls only.

The FieldValue(controlName) method for multi-lookup controls returns the value in the ID1;TITLE1;#ID2;#TITLE2;#… format.

This method returns all the ID parts inside the value, concatenated by the separator provided as a parameter.

For example:

Code

var value = form.FieldValue(“c_Multi”);

// returns “1;#Open;#2;#Closed”

var value2 = form.FieldValues(“c_Multi”, “,”);

// returns “1,2”

FieldNames(controlName, separator)

Return type : string

This method is used for multi-lookup controls only.

The FieldValue(controlName) method for multi-lookup controls returns the value in the ID1;TITLE1;#ID2;#TITLE2;#… format.

This method returns all the TITLE parts inside the value, concatenated by the separator provided as a parameter.

For example:

Code

var value = form.FieldValue(“c_Multi”);

// returns “1;#Open;#2;#Closed”

var value2 = form.FieldNames(“c_Multi”, “,”);

// returns “Open,Closed”

UserID()

Return type : string

This method returns the ID of the current SharePoint user.

Example :

Code

var id = form.UserID();

UserFullName()

Retutn type : string

Returns the name of the current user

Example :

Code

var name = form.UserFullName();

LoginName()

Retutn type : string

Returns the login name of the current user

Example :

Code

var name = form.LoginName();

UserInGroup(idOrName)

Return type : bool

Retutns true if the current user belongs to a group having the provided id or name.

Example :

Code

var granted = (form.UserInGroup(“Administrators”) || form.UserInGroup(“2”));

CurrentUser()

Return type : object

Returns a structure containing information about the current user.

User Properties :

ID, FullName, LoginName, Email, Groups (array of groups)

Group Properties

ID, Name

Example :

Code

var user = form.CurrentUser();

var userId = user.ID;

for (var i=0;i<user.Groups.length;i++) {

var group = user.Groups[i];

var groupName = group.Name;

}

IsNewRecord()

Return type : bool

Returns true if we are currently in a new record, otherwise it retuns false.

Example :

Code

if (form.IsNewRecord() && form.FieldValue(“c_Title”) == “”)

alert(“Title must be provided for new records”);

ViewMode()

Return type : bool

Returns true if the form is in view mode. This is important to know specially when dealing with script that enables controls.

Example :

A script like the following written inside the LoadCompleted script of the form, would have the result that the specific control would be enabled even when the form is in ViewMode.

Code

var status = form.DataItem.Status;

var control = form.GetControl(“c_Title”);

// Wrong

if (status == “Open”) control.SetEnable(true);

else control.SetEnable(true)

// Correct

if (form.ViewMode() == false) {

if (status == “Open”) control.SetEnable(true);

else control.SetEnable(false);

}

ShowMessage(message)

Return type : None

Displays a short message in a placeholder between the toolbar and the form.

It may be used to provide alerts and instructions to the end user.

Example :

Code

form.ShowMessage(“Password must be at least 6 characters long”);

MessageForm(message, title, callback)

Return type : None

Shows a modal popup message form to the user.

The message and title parameters are used to set the body and title of the dialog.

If a callback method is specified, the callback is executed when the users closes the form.

Example :

Code

form.MessageForm(“There has been an error saving data”, “Error”, function(e) {

form.CancelRecord();

});

CloseMessageForm()

Return type : None

Closes the above message form programmatically.

Example :

Code

form.CloseMessageForm();

 

ShowButton(buttonName)

Return type : None

Shows a toolbar button.

In order for this method to work, the user must first have the appropriate rights to press that button and the designer of the form must have allowed this button to be available on the form.

Example :

Code

form.ShowButton(“delete”);

Available button names (Case Insensitive) : “New”, “Save”, “SaveAndExit”, “Delete”, “Cancel”, “Edit”, “Help”, “Design”, “Print”

HideButton(buttonName)

Return type : None

Hides a button from the toolbar.

Available button names (Case Insensitive) : “New”, “Save”, “SaveAndExit”, “Delete”, “Cancel”, “Edit”, “Help”, “Design”, “Print”

Example :

Code

form.HideButton(“Save”);

form.HideButton(“SaveAndExit”);

RequestValue(key)

Return type : string

Searches inside the window querystring to find a key matching the specified parameter.

It returns the value of the querystring parameter.

For example (assuming a page with the url : “http://servername/Lists/EditPage.aspx?IsDlg=1”)

Code

var value = form.RequestValue(“IsDlg”);

// returns “1”

SendEmail(to, subject, body, callback)

Return type : None

Uses the SharePoint infrastructure to send an email. The callback (optional) will be executed as soon as the operation completes.

Example :

Code

var sub = form.GetControl(“c_EmailSubject”).GetValue();

var to = form.GetControl(“c_EmailTo”).GetValue();

var body = form.GetControl(“c_EmailBody”).GetValue();

form.SendEmail(to, sub, body, function(e) {

var ok = e.Success;

if (!ok) alert(“Error sending email : ” + e.ErrorMessage);

});

The variable that will be passed to the callback will have the following properties :

Success : Type = bool
ErrorMessage : Type = string

CallWebService(wsName, callback)

Return type : None

Used to manually execute a predefined web service.

Example :

In the following example we call a predefined web service targeting the _vti_bin/Lists.asmx default service of SharePoint. Inside the callback, it checks for any errors and then loops all the results to create a single <a> hyperlink for each list retrieved.

Code

function callback(e) {

var c = form.GetControl(“c_WSResult”);

var s = “”;

if (pf.IsEmpty(e.ErrorMessage)) {

for (var i=0;i<e.ListItems.length;i++) {

if (i>0) s+=”, “;

s += “<a href=\”#\” onclick=\”w = window.open(‘http://wssdev1/Lists/” + e.ListItems[i].Title + “‘,”,’width=800,  height=600, resizable=yes, scrollbars=yes’);\” style=\”color:#cc6600\”>” + e.ListItems[i].Title + “</a>”;

}

c.SetValue(s);

}

else { c.SetValue(e.ErrorMessage); }

form.GetControl(“c_WSButton”).SetEnable(true);

}

form.GetControl(“c_WSButton”).SetEnable(false);

form.CallWebService(“All Lists”, callback);

ExecuteSQLQuery(queryName, callback)

Return type : None

Used to manually execute a predefined SQL query.

Example :

Code

function callback(e) {

var c = form.GetControl(“c_SQLResult”);

var s = “”;

if (pf.IsEmpty(e.ErrorMessage)) {

for (var i=0;i<e.ListItems.length;i++) {

if (i>0) s+=”, “;

s += e.ListItems[i].NAME;

}

c.SetValue(“<strong>” + s + “</strong>”);

}

else {

c.SetValue(e.ErrorMessage);

}

}

form.ExecuteSQLQuery(“Products”, callback);

 

LoadListQuery(listQueryName,callback)

Return type: None

Used to manually execute a predefined list query.

Example:

Code
function callback(e) {
  var s = “”;
  if (pf.IsEmpty(e.ErrorMessage)) {
    for (var i=0;i<e.ListItems.length;i++) {
      if (i>0) s+=”, “;
      s += e.ListItems[i].Title;
    }
  }
  else {
      s = e.ErrorMessage;
  }
  alert(s);
}
form.LoadListQuery(“Products”, callback);

 

LoadRecords(listUrl, listIdOrName, viewIdOrName, criteria, fieldsToRetrieve, sortField, sortAscending, rowLimit, callback)

Return type : None

Used to manually load an array of list items based on specified criteria. The criteria is an array of pf.SearchSpec objects. The “fieldsToRetrieve” parameter is a string array of field names; if null then all fields are returned. If row is greater than zero then all rows are returned.

Example:

Code

 

function callback(e)
{
  if (e.ErrorMessage)
  {
     alert(e.ErrorMessage);
  }
  else
  {
    if (e.ListItems.length > 0)
    {
     alert(“ID:” + e.ListItems[0].ID + ”   Title:” + e.ListItems[0].Title);
   }
    else
    {
       alert(“no items found”);
    }
  }
}

criteria = [];

var ss = new pf.SearchSpec();
ss.FieldName = “Title”;
ss.FieldValue = “Test”;
ss.Operator = “Contains”;  //Equals,NotEquals,Greater,GreaterOrEqual,Less,LessOrEqual,IsNull,IsNotNull,BeginsWith,Contains,In, DateRangesOverlap
ss.Type = “Text”;
criteria.push(ss);
form.LoadRecords(“http://bpcspdev”, “TestList”, “”, criteria, null, null, false, 0, callback);

 

 

LoadRecord(listUrl, listIdOrName, itemId, callback)

Return type : None

Used to manually load a list item through script based on its ID.

 

Example:
Code

function callback(e)

{
  if (e.ErrorMessage)
  {
    alert(e.ErrorMessage);
    return;
  }
  if (e.ListItem)
  {
    alert(“Item ID:” + e.ListItem.ID + “, Title:” + e.ListItem.Title);
  }
}

 

form.LoadRecord(“http://bpcspdev”, “TestList”, 7, callback);

 

DeleteRecords(listUrl, listIdOrName, viewIdOrName, specs, sortField, sortAscending, rowLimit, callback)

 

Return type : None

Used to delete an array of list items based on specified criteria.

The url of the list, the list title or the view id of the records must be passed as parameters. The criteria (specs) is an array of pf.SearchSpec objects.

 

Example:

Code
function callback(e)
{
  if (e.ErrorMessage)
  {
     alert(e.ErrorMessage);
  }
  else
  {
    if (e.ListItems.length > 0)
    {
     alert(“all items have been deleted!”);
   }
    else
    {
       alert(“no items found!”);
    }
  }
}

criteria = [];

var ss = new pf.SearchSpec();
ss.FieldName = “Title”;
ss.FieldValue = “Test”;
ss.Operator = “Contains”;  //Equals,NotEquals,Greater,GreaterOrEqual,Less,LessOrEqual,IsNull,IsNotNull,BeginsWith,Contains,In, DateRangesOverlap
ss.Type = “Text”;
criteria.push(ss);

 

form.DeleteRecords(“http://bpcspdev”, “TestList”, “”, criteria, null, null, false, 0, callback);

 

 

DeleteRecord(listUrl, listIdOrName, itemId, callback)

Return type : None

Used to delete a record inside a list.

The url of the list, the list title and the id of the record must be passed as parameters.

Example :

Code

form.DeleteRecord(“http://servername”, “Customers”, “2”, function(e) {

if (!pf.IsEmpty(e.ErrorMesage)) alert(“Error occurred : ” + e.ErrorMessage);

});

DeleteCurrentRecord(confirm)

ReturnType : None

Used to delete the current record. It takes a parameter to force or ommit the confirmation message presented to the end user.

Example :

Code

form.DeleteCurrentRecord(false);

CancelRecord()

Return type : None

It has the same effect with that when the user presses the Cancel button in the toolbar.

Example :

Code

form.CancelRecord();

SaveRecord() or SaveCurrentRecord()

Return type : None

Saves the current record. The method has the same effect with that when the users press the “Save” button.

Validations are applied to the form data (either required fields or custom validation code from script)

Example :

Code

form.SaveRecord();

SaveRecord(url, listIdOrName, listItem, callback)

Saves the provided list item. The item should be a javascript object having properties named after the column names we want to update.

Example :

Code

var item = new Object();

item.Title = “New Item”;

item.Status = “Open”;

item.Category = “1;#Category A”;

form.SaveRecord(“http://servername”, “listA”, item, function (e) {

var error = e.ErrorMessage;

var newItem = e.ListItem;

});

SaveAndExit()

Return type : None

Performs the same action which is performed by the Save-and-Close button of the toolbar.

Example :

Code

form.SaveAndExit();

GetSectionByKey(key)

Return type : FormSection object

Returs a section object that matches the key provided.

Each section in a form may have an identifier key (you can set this up using the appropriate section-properties form inside the run-time designer)

Example

Code

var section = form.GetSectionByKey(“Main”);

if (section != null) section.Collapse();

ExpandSection(sectionKey)

Return type : None

Expands a form section.

Example :

Code

form.ExpandSection(“SectionA”);

CollapseSection(sectionKey)

Return type : None

Collapses a form section

Example :

Code

form.CollapseSection(“SectionA”);

HideSection(sectionKey)

Return type : None

Hides a form section

Example :

Code

if (!form.UserInGroup(“Administrators”))

form.HideSection(“SectionA”);

ShowSection(sectionKey)

Return type : None

Shows a form section that is hidden

Example :

Code

if (form.UserID() == “1”) form.ShowSection(“SectionA”);

else form.HideSection(“SectionA”);

GetControl(controlName)

Return type : FormControl object

Searches the form for a control with the name passed as a parameter.

Returns the control object found or null if no control matches the specified name.

The control object returned has its own methods described here :

Control Properties and Methods

Example:

Code

var c = form.GetControl(“c_Status”);

var value = c.GetValue();

if (value == “Closed”) form.GetControl(“c_Priority”).SetValue(“Low”)

 

GetControlByTargetFieldName(columnName)

ReturnType : FormControl object

Searches inside the form controls to find one that is bound to the specified list column name.

Example :

Code

var c = form.GetControlByTargetFieldName(“Title”);

if (c != null) c.SetValue(“”);

HideTab(index)

ReturnType : None

Hides a tab item by its index (the index is zero based).

Example :

Code

form.HideTab(1);

ShowTab(index)

ReturnType : None

Shows a tab item by its index (the index is zero based).

Example :

Code

form.ShowTab(1);

SetSectionBorderThickness(key, thickness)

Return Type : None

Changes the thickness of a section border.

Parameters :

key : The section key

thickness : The border thickness

Example :

Code

form.SetSectionBorderThickness(“main”, “3px”);

SetSectionBorderColor(key, color)

Return Type : None

Changes the color of a section border.

Example :

Code

form.SetSectionBorderColor(“main”, “#336699”);

SetSectionBackColor(key, color)

Return Type : None

Changes the background color of a section.

Example :

Code

form.SetSectionBackColor(“main”, “#F5F5A5”);

SetSectionCellSpacing(key, spacing)

Return Type : None

Changes the cell spacing of the table inside a section.

Example :

Code

form.SetSectionCellSpacing(“main”, 3);

SetSectionCellPadding(key, padding)

Return Type : None

Changes the cell padding of the table inside a section.

Example :

Code

form.SetSectionCellPadding(“main”, 3);

 

SetSectionHeader(key,content)

Return Type : None

Changes the contents of a section’s header.

Example :

Code

form.SetSectionHeader(“A0”, “<span class=’title’>Companies</span>”);

 

Attachments() and AttachmentsLoaded event

The Attachments method returns an array of the loaded attachment objects.

Each attachment includes the Filename and FullPath  properties.

Example script written inside the LoadCompleted event of the form that produces thumbnails for all the image attachments of the current list item:

Code
form.AttachmentsLoaded.AddHandler(function(files) {

var s = “”;

var c = form.GetControl(“c_Attachments”);

for (var i=0;i<files.length;i++) {

var name = files[i].FullPath;

var suf = name.substring(name.length – 3, name.length).toLowerCase();

  if (suf == “png” || suf == “gif” || suf == “jpg” || suf == “bmp”)

s = s + “<span style=’padding:10px’><a href='” + files[i].FullPath + “‘ target=’_blank’ style=”><img src='” + files[i].FullPath + “‘ width=’32’ height=’32’ style=’border:0px’ /></a></span>”

}

c.SetValue(s);

});

 

 

SetTabHeader(Tab Ident Number, an HTML span containing the text which also sets the visual properties)

Return Type : None

Changes a tab’s header properties.

Example :

Code

form.SetTabHeader(0, “<span style=’font-size:19px;padding:5px;cursor:pointer;color:#3399FF;’>My Best Form</span”);

 

 

Url()

 

Return Type : String

Returns the form’s list Url. Can be used in script and formulas.

Example :

Code

var mySiteUrl = form.Url();

 

 LoadCurrentUser(Web site Url, callback function)

 

Return Type : Object

Returns the current user’s information in a User object.

User Object:

– LoginName (string)

– ID (string)

– FullName (string)

– IsSiteAdmin (boolean)

– Email (string)

– Groups (object)

Example :

Code

 

function callback(e)
{
 var i = e.User.LoginName + “,” + e.User.ID + “,” + e.User.FullName + “,” + e.User.Email;
 alert(i);
}
form.LoadCurrentUser(“http://bpcspdev/DimThen”,callback);

 

 

CopyFile(sourceUrl, sourceList, docID, targetUrl, targetList, targetFolder, targetFileName, attributes, overwrite, callback)

 

Return Type : None

Copies a document from one document library to another.

Example :

Code
form.CopyFile(“http://devserver”, “Shared Documents”, “13”, “http://devserver/site”, “Reports”, “Folder1”, “Test.doc”, {Title: “My Title”, Category: “Drafts”}, true, function(e) {

alert(“Document Copied”);

});

 

 SetAttachmentGridHeight(height)

Return Type : None

Adjusts the height of the grid containing item attachments.

Example :

Code

form.SetAttachmentGridHeight(“400px”);

 

GetTab(Tab Number)

Return Type: Object

Returns the selected tab’s object. The parameter Number is zero-based, meaning that if you want to select the first tab appearing on form, you have to do the following:

Code

 form.GetTab(0);

 

SetDisplayMode(mode)

Return Type: None

Accepts two parameters: Flat and Normal

Flat mode turns the form into a single page, with every control listed beneath each other, meant to be used for easier page printing.

Code

form.SetDisplayMode(“Flat”);

 

ToggleDisplayMode()

Return Type: None

Switches between Flat and Normal page mode.

Code

form.ToggleDisplayMode();

 

Log(string message)

Return Type: None

This command is meant to be used with the debugging form (_log=1), allowing you to print a message in the debugging box.

Code

form.Log(“Test message!”);

 

OpenUrl(url, caption, width, height, x, y, callback)

Return Type: None

You can use this command to open a new pop-up window, which will navigate to the appointed URL path. You can also include a callback function, which will fire, once the form finishes loading.

 

Code
form.OpenUrl(“http://www.google.com”, “Caption”, 1000, 1000, “10”, “10”, callback);

 

function callback(e){
 alert(“Done”);
}

SelectedTabIndex()

Return Type: Integer

You can use this command to find out the index number of the currently selected Tab. The selected tab index is zero-based, meaning the first tab will return 0, the second tab will return 1 etc.

 

Code
form.SelectedTabIndex();

 

HideInnerTab(key, index)

Return Type: None

You can use this command to hide a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0 and the key is the name of it.

 

Code
form.HideInnerTab(“c_InnerTabKey”, 0);

 

ShowInnerTab(key, index)

Return Type: None

You can use this command to show a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0 and the key is the name of it.

 

Code
form.ShowInnerTab(“c_InnerTabKey”, 0);

 

SelectInnerTab(key, index)

Return Type: None

You can use this command to select a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0 and the key is the name of it.

 

Code
form.SelectInnerTab(“c_InnerTabKey”, 0);

 

SelectedInnerTabIndex(key)

Return Type: Integer

You can use this command to find out the index number of the currently selected Inner Tab. The selected inner tab index is zero-based, meaning the first tab will return 0, the second tab will return 1 etc.

 

Code
form.SelectedInnerTabIndex(“c_InnerTabKey”);

 

DisableInnerTab(key, index)

Return Type: None

You can use this command to disable a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0 and the key is the name of it.

 

Code
form.DisableInnerTab(“c_InnerTabKey”, 0);

EnableInnerTab(key, index)

Return Type: None

You can use this command to enable a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0 and the key is the name of it.

 

Code
form.EnableInnerTab(“c_InnerTabKey”, 0);

SetInnerTabHeader(key, index, text)

Return Type: None

You can use this command to set a new header text to a specific Inner Tab. The inner tab index is zero-based, meaning the first tab will be 0, the key is the name of it and the text is the new header.

 

Code
form.SetInnerTabHeader(“c_InnerTabKey”, 0, “NewHeader”);

LoadGroupsInSite(url, callback)

Return Type: Array of Objects

You can use this command to load a site’s SharePoint groups. The command accepts two parameters, the site url and a callback function which you can use to retrieve any information you require.

The returned objects contain the following group information:

–  ID [number]

–  IsGroup [boolean]

–  Name [string]

– LoginName [object]

– Email [object]

– IsSiteAdmin [boolean]

– Type [object]

– uid [string]

Since this is a complicated function, we will use an example to explain its usage. Our example contains a Combobox control, which we will use to load the Group names, called c_Groups and a button, which will use the following script to load every group in the site.

Use the following script in the button’s Action property to load the c_Groups Combobox with the group names:

Code
if(!pf.IsEmpty(form.Url()))
{
    var theSiteURL = form.Url();
    function loadGroupsCallback(e)
    {
        var cmb = form.GetControl(“c_Groups”).InputControl;
        var groups = [];
        for (var i=0; i < e.PeopleAndGroups.length; i++)
        {
           groups.push(e.PeopleAndGroups[i].Name);
        }
        cmb.SetDataSource(groups);
    }

 

    form.LoadGroupsInSite(theSiteURL, loadGroupsCallback);
}

LoadUsersInGroup(url, groupName, callback)

Return Type: Array of Objects

You can use this command to load a SharePoint group’s Users. The command accepts three parameters, the site url, the group’s name and a callback function which you can use to retrieve any information you require.

The returned objects contain the following group information:

– LoginName [string]

–  ID [string]

–  FullName [string]

– IsSiteAdmin [boolean]

– Email [string]

– Groups [object]

– uid [string]

Again, since this is a complicated function, we will continue using the above example to explain its usage. Our example above contained a Combobox control, which we used to load every group name in the site. Following this, we will add a DataGrid called c_UsersInGroup, which we will use to show the login name and the full name of every user in the selected group. We will also add another button, which will call the LoadUsersInGroup function.

Use the following script in the button’s Action property to populate the datagrid:

Code
var theSiteURL = form.Url();

 

form.LoadUsersInGroup(theSiteURL, form.GetControl(“c_Groups”).GetValue(), callback);

 

function callback(e) {
    var grid = form.GetControl(“c_UsersInGroup”).InputControl;
    var users = [];

 

    if (pf.IsEmpty(e.ErrorMessage)) {
        for (var i = 0; i < e.Users.length; i++) {
            users.push({ LoginName: e.Users[i].LoginName, FullName: e.Users[i].FullName });
        }
        grid.SetDataSource(users);
    }
    else
        alert(e.ErrorMessage);
}

AddUserInGroup(url, groupName, username, callback)

Return Type: none

You can use this command to add a user to a SharePoint group. The command accepts four parameters, the site url, the group’s name, the user’s name and a callback function which you can use to retrieve the success or failure of the operation.

Code
var theSiteURL = form.Url();

 

form.AddUserInGroup(theSiteURL, “example site Members”, “ExampleSiteDomain\\ExampleUser”, callback);

 

function callback(e) {
    if (pf.IsEmpty(e.ErrorMessage)) {
        alert(“Success”);
    }
    else
        alert(e.ErrorMessage);
}

DeleteUserFromGroup(url, groupName, username, callback)

 

Return Type: none

You can use this command to remove a user from a SharePoint group. The command accepts four parameters, the site url, the group’s name, the user’s name and a callback function which you can use to retrieve the success or failure of the operation.

Code
var theSiteURL = form.Url();

 

form.DeleteUserFromGroup(theSiteURL, “example site Members”, “ExampleSiteDomain\\ExampleUser”, callback);

 

function callback(e) {
    if (pf.IsEmpty(e.ErrorMessage)) {
        alert(“Success”);
    }
    else
        alert(e.ErrorMessage);
}

SetAttachmentTabHeader(theHeaderText)

 

Return Type: none

You can use this command to change the header in the Attachments tab. The command accepts one parameter, a string value.

You can use the following code in the form’s Load Completed script:

Code

form.SetAttachmentTabHeader(“My Attchments”);

 

AddToolbarButton(icon, text, style, position)

 

Return Type: none

You can use this command to create a custom button on the form’s toolbar section. You can also set the button in such a way, that it performs various actions. The command accepts four parameters:

– icon:  The icon’s path, as a string value.

– text: The text to appear beneath the icon.

– style: Defines the button’s style. Possible values can be:

– An empty string, which will create a default button, with an icon and a text underneath.

– “tiny” will create a button with a small icon.

– “tinynotext” will create a button with a small icon and no text underneath.

– “notext” will create a button with a normal-sized icon and no text underneath.

– position: Use form.TOOLBAR to place it next to the other form toolbar buttons.

 

As an example, we will create a custom button, place it at the end of the toolbar section and make sure that each time you press it, the form will save all data.

You can use the following code in the form’s Load Completed script:

Code
if (form.BUTTON_TEMPSAVE == null) {
    // adding toolbar buttons
    var imgName = form.Url() + “/Form%20Pictures/saveimg.png”;
    var txt = “Temp Save”;
    var style = “”;
    form.BUTTON_TEMPSAVE = form.AddToolbarButton(imgName, txt, style, form.TOOLBAR);
    form.BUTTON_TEMPSAVE.onclick = function (e) {
        form.SaveRecord();
    };
}

 

GetTabHeader(index)

Return Type: string

You can use this command to retrieve the header text from a tab. The command accepts one parameter, an index number representing the tab’s order of appearance. The index is zero based, meaning that the first tab is 0, the second is 1 etc.

 

You can use the following code in the form’s Load Completed script:

Code
var rr = form.GetTabHeader(0);
alert(rr);

 

SetTranslation(key, value)

Return Type: none

You can use this command to change the textual representation of any standard control on the form. You normally would do this using the Localization section in the designer form, but you can also do the same programmatically using this function.

 

The function accepts two parameters, the Key part will be the key part from the Localization section and the value would be the textual representation you wish to use.

 

For example, we will change the text part of the form’s New Record button.

 

You can use the following code in the form’s Form Design Loaded script:

Code

form.SetTranslation(“Form_NewRecord”, “Something irrelevant”);

 

DisableAttachments()

Return Type: none

You can use this command to disable the use of the Attachments tab.

Code

form.DisableAttachments();

 

EnableAttachments()

Return Type: none

You can use this command to enable the use of the Attachments tab.

Code

form.EnableAttachments();

, ,

Using the format painter to copy control formatting

The format painter is a tool used to copy a control’s format to multiple controls. You can use it to easily create identical controls, without the need to build them from scratch every time.

The field Title has a red background, which we want to copy to another control present on the form.

 

We enter the Editor, select the c_Title field and press on the Format Painter icon.

 

The standard pointer changes to a black dot. We use the black dot to click on the controls we want to copy c_Title’s red background format. We select c_Control1 and click on Save.

 

As we can see, the Date has a red background.

, ,

PowerForms and Browser Compatibility

BPC PowerForms supports all major browsers (Internet Explorer 7 and above, Chrome, Firefox, Safari and Opera), however, if you are using Internet Explorer, then the user experience is much more smooth and user-friendly in versions 8 and above. on your clients when interacting with PowerForms for much better experience.

 

When IE8 or above loads in compatibility view, it behaves like IE7, sending the corresponding headers to the web server. Due to this fact, we strongly recommend that make sure that you disable IE compatibility view for your SharePoint site

 

By default, SharePoint 2010 master pages will be rendered in IE8 mode. However, Internet Explorer 8 and 9 have a default setting that forces compatibility view to all intranet sites, even if the site itself chooses another browser mode. If your clients have your SharePoint farm’s sites in Intranet zone, then you are recommended to uncheck the “Display Intranet Sites in Compatibility View” option in Tools (Alt+T)  => Compatibility View Settings: