Loading...

Custom Actions Examples.

Title

Custom Actions Examples.

Description

Custom Actions Examples.

Please wait...

The Custom Action capability enables you to write a custom code that can be called from qListView, qListForm, qSIListView or qSIListForm Web Parts. In your custom code, you can virtually do anything you want with the data. For example:
• You can write a complex custom validation and abort the action if the data is invalid.

• You can copy the item to another list or library before the item is saved in a qListForm.

• You can initialize one or more fields in the qListForm when the list form is initialized. Please see the Form Initialization Actions property of the qListForm and qSIListForm on how to call this kind of custom action. Please also see the code example below on how to write a custom action to initialize the list form.

Resolution

Here are examples of code showing how you can trigger the encryption based on field name, field type or field name convention.

//the Field Name is known
if (item["SIN"] != null)
{
item["SIN"] = EncDec.Encrypt(item["SIN"].ToString());
}

//Field Name is unknown but we know th type of the field we want to encrypt
SPFieldCollection flds = item.Fields;
foreach (SPField fld in flds)
{
if (fld.GetType() == typeof(SPFieldText) && item[fld.StaticName] != null)
{
item[fld.StaticName] = EncDec.Encrypt(item[fld.StaticName].ToString());
}
}

// FiedlName is unknown but we know the field name pattern of the fields we want to encrypt
foreach (SPField fld in flds)
{
string sFieldName = fld.StaticName;
if (CanEncrypt(sFieldName) && item[fld.StaticName] != null)
{
item[fld.StaticName] = EncDec.Encrypt(item[fld.StaticName].ToString());
}
}

 

Leave a Reply