Tags: , , , | Posted by Yannis Sovolakis on 5/23/2011 12:40 AM | Comments (0)
Scripting has always been a powerful tool to perform customizations and extend the capabilities of any application.
In the next release of BPC PowerForms for SharePoint (coming June 2011), scripting with IronPython will be integrated. For the time being, the following events may be handled through scripting :
  • Control Value Change
  • Form Validation
  • Form Load Completed


In this article, we will try to have a first look of this new powerful feature.
Let's have scripting in action through a simple example:
We want to build a simple "Issue" register, where High priority Issues must follow certain rules.
First we must create a custom list called "Issues" with some of the obvious columns :
  • Title
  • Description (multiple  lines of plain text)
  • Priority (choice - Normal, High, Low)
  • Owner (people picker)
  • Estimated Effort
  • Status (choice - Submitted, Asigned, Resolved, Canceled)
  • Resolution (multiple lines of text)
Next we must register PowerForms in our new list using the Settings menu. (SharePoint 2007 has been used for the example).
As soon as we register PowerForms for the NEW and EDIT form, we start with some simple customizations by opening the New form.
We open the designer and some basic customizations include :
  • Adding a new Tab for the Resolution field
  • Change the section appearance in the first tab (column widths, borders, etc)
  • Changing the size of controls
Our new form should be something like the following image:
Now we want to add 2 more customizations :
  1. Make the OWNER field REQUIRED when Priority is HIGH
  2. Change OWNER control appearance indicating that the controls is required whenever the user changes the value in the Priority field
In order to achieve the first, we must add a validation script in the form itself. We must open the designer and select OPTIONS from the Section selector. At the bottom of the form, 2 fields can hold scripts for form actions : "Validate Script" and "Load Completed Script".
The "Validation Script" is called whenever the user tries to save the record. In order to allow the user applying the scripting to cancel the action, inside the script, we should introduce 2 variables:
  • result (it should be set to True or False indicating if the validation passed or not)
  • error (it is a string variable, keeping the error message in case the validation fails)
In order to assist the user to write the script, the system automatically passes a system variable called "template" that represents the form design. The most usefull method of template is the GetControl(string) method that gets a reference to a single control using the control name.
In order to get the value of a control, we can cal the GetValue() method.
So we apply the following script in the "Validate Script" field :
import clr
result = True
error = ""
control = template.GetControl("c_Priority")
c_Owner = template.GetControl("c_Owner")
if control.GetValue() == "High" and c_Owner.GetValue_Value() == "" :
  result = False
  error = "High Priority requires to define the Owner of the Issue"
else :
  result = True
  error = ""
 As you can see, we initialize the "result" and "error" variables and then we write a simple checking script that raises an exception if the Priority field is set to High and the Owner field is blank.
Note that we use the GetValue_Value() method which only retrieves the ID part of a lookup control. The GetValue() method would return the value in the "ID;#NAME" format.
We save the designer and test our script.
If we try to save a record with High Priority and no Owner, the following message should appear:
Now we want to make it obvious to the user that the Owner field is required under certain conditions.
We open the designer again and select the properties of the Priority control. Under the "Scripts" tab, we should apply the following script which does the trick:
value = control.GetValue()
owner = template.GetControl("c_Owner")
if value == "High" :
else :
For the Value Change script, an additional variable is passed called "control" that corresponds to the control firing the ValueChange event (in our case the c_Priority control).
The script is simple enough.
As you can see, all we do is to test the Priority value and if it is High, we change the background, and border of the control, otherwise reset them back to the original values.
We save the designed form and watch the result :


when selecting High priority or otherwise :


Ok that's it for now. A complete reference of the scripting capabilities will follow as well as more advanced examples. Since IronPython is a powerful tool in our hands, we think that the potentials are great.

Add comment

  Country flag
  • Comment
  • Preview