Script Examples
The above system columns do not create bound controls during form initialization.
You can get the values though through script and set these values inside your custom controls through script :
You should add the following script in the “Load Completed” script of the form : Designer > Options > Scripting > Load Completed
created = dataitem.GetValue(“Created”)
template.GetControl(“c_Created”) .SetValue(created)
modified = dataitem.GetValue(“Modified”)
template.GetControl(“c_Modified”) .SetValue(modified)
# THE RETRIEVED VALUE IS IN THE ID;#TITLE FORMAT
author = dataitem.GetValue(“Author”)
# GET THE ID PART
authorId = dataitem.GetValue_Value(“Author”)
# GET THE TITLE PART
authorName = dataitem.GetValue_Name(“Author”)
template.GetControl(“c_Author”) .SetValue(authorName)
editor = dataitem.GetValue(“Editor”)
template.GetControl(“c_Editor”) .SetValue(editor)
You can enable, disable, show or hide tabs through script.
So in the Load Completed script or in the Value Change event of a control, you can write something like the following :
If template.Functions.UserInGroup(“Admins”) :
template.ShowTab(1)
template.EnableTab(2)
template.HideSection(3)
else :
template.HideTab(1)
template.DisableTab(2)
template.ShowSection(3)
Note : the template.Functions property includes the functions used from formulas too :
string ColumnDescription(string colInternalName)
string ColumnTitle(string colInternalName)
string ColumnType(string colInternalName)
bool ColumnIsRequired(string colInternalName)
string FieldValue(string controlName)
string FieldDisplayValue(string fieldname)
string FieldValue_Value(string controlName)
string FieldValue_Name(string controlName)
string LoginName()
string UserID()
string UserFullName()
bool UserInGroup(string groupName)
bool UserInGroupById(string groupId)
string ListName()
string ListId()
string ListUrl()
There are cases that you need to set the value to 2 controls (from script) with the second being affected by the first one.
For example you have 2 dropdown controls (ComboBoxes, LookupPickers, etc) one for Countries and one for Cities.
The Cities combo is affected by the Countries combo, meaning that when the user selects a Country, the Cities combo is forced to reload its data.
If you try to set the values to both controls using the following script, it should fail for the Cities combo since the time we are setting the value, the combo values are not loaded yet (loading is asynchronous).
# THIS CODE WILL NOT WORK
template.GetControl(“c_Countries”).SetValue(“1;#Country1”)
template.GetControl(“c_Cities”).SetValue(“34;#City34”)
For that reason a new method has been introduced which set the value to a lookup control and the control will set the value as soon as loading is complete.
The method is called : SetValueOnLookupLoaded
The folloing script will work as expected.
template.GetControl(“c_Countries”).SetValue(“1;#Country1”)
template.GetControl(“c_Cities”).SetValueOnLookupLoaded (“34;#City34”)
The ListDataGrid control includes some useful methods which can be used through script:
# PROPERTY THAT RETURNS ALL THE DATA RECORDS OF THE GRID
items = c.InputControl.DataItems
count = items.Count
id = items[0].GetValue(“ID”)
# RELOAD GRID
c.InputControl.SetValue(“”)
# OR
c.InputControl.RefreshData()
# GET A VALUE FROM THE SELECTED RECORD
c.InputControl.GetGridItemValue(“ID”)
# SELECT A ROW BY INDEX
c.InputControl. SelectGridRow(3)
# SELECT A RECORD BY A VALUE EXAMPLE
id = template.GetControl(“c_ID”).GetValue()
grid = template.GetControl(“c_DetailData”)
count = grid.InputControl.DataItems.Count
grid.InputControl.SelectGridItem(None)
for i in range(0, count) :
item = grid.InputControl.DataItems[i]
if item.GetValue(“ID”) == id :
grid.InputControl.SelectGridItem(item)
In order to set the value of a control during form initialization (usually for new records) you can use 3 different methods.
- Set a default value for that control
- Pass the value in the querystring
- Use script
To set the value you must use the LoadCompleted script and add something like the following :
# The “dataitem” variable references the record being displayed
# For new records, it will only contain the default values in ColumnName/Value pairs
# Only for New records set the priority to HIGH
if dataitem.GetValue(“ID”) == “” :
dataitem.SetValue(“Priority”, “High”)
