ImageWIKI
RSS

Navigation



Tags
1_2 2011 4_0 4_1 4_1_0_10 4_1_0_11 4_1_0_9 4_2 4_2_0_0 4_2_0_1 4_2_0_5 Android BlackBerry CRM 3_0 CRM 4_0 CRM Online Default Sales Profile Exchange Connector FAQ General Guides HOWTO Installation iPhone KB Mobile Express Private Sample SDK Server TODO troubleshooting Windows Mobile

Other Links
CWR Mobility Website
CWR Mobility Blog




Quick Search » Advanced Search »

PoweredBy
This page is a Draft, its content is not complete and might contain errors.

This article applies to:
  • CWR Mobile CRM 4.2


Table of Contents [Hide/Show]


Capabilities

The Scripting SDK allows customization of the behaviour of CWR Mobile forms in the Windows Mobile Client. The scripting SDK is intended only for simple customizations such as:
  • validation of text formats
  • comparative validating of two fields
  • automatically setting a field value based on an other field
  • formating fields
  • dynamically changing the requirement level of a field

Limitations

The scripting SDK allows access to a sub set of functions and types available in the full SDK. The available types include the System.Text.RegularExpression namespace and the System.Math class. All standard C# constructs (if, for, while, switch) can be used.
It is not possible to create classes, access webservices or use external (.NET) libraries.

For the full support of all features of the .NET framework and the CWR Mobile SDK custom controls must be developed. For more information: see Custom Controls.

Interface



public interface IField
{
     bool IsReadOnly { get; set; }
     RequirementLevel RequirementLevel { get; set; }
}

public interface IScriptFormContext
{
     IField GetField(string name);
     bool IsNewRecord { get; }
     bool IsReadOnly { get; }
     bool IsDirty { get; }
     string ObjectTypeName { get; }

     object GetValue(string fieldName);
     void SetValue(string fieldName, object value);
}

public interface MessageBox
{
     public static DialogResult Show(string text);
     public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
}

Examples

A number of examples:
  • Postal code validation. To be used in the OnChange method of the field.
  • Field validation.To be used in the OnSave method of the form.
  • Read-only. To be used in the OnLoad method of the form.

Postal code validation

This script can be placed in the "OnChange" handler of a text field and will format the input.

string original = (string) Form.GetValue("address1_postalcode");
Match match = Regex.Match(original, @"(?[0-9]{4})\s+(?[A-Za-z]{2})");

if (match.Success)
{
  Form.SetValue("address1_postalcode", string.Format("{0}{1}", match.Groups["digits"].Value, match.Groups["letters "].Value));
}
else
{
  MessageBox.Show("Invalid postal code");
}

Setting requirement level

This script changes the requirement level of other fields when it is triggered in the "OnChange" method.

if (((Picklist)Form.GetValue("address1_shippingmethodcode")).Value == 5)
{
    Form.GetField("address1_line").RequirementLevel = RequirementLevel.Required;
    Form.GetField("address1_city").RequirementLevel = RequirementLevel.Recommended;
    Form.GetField("address1_postalcode").RequirementLevel = RequirementLevel.Recommended;
}
else
{
    Form.GetField("address1_line").RequirementLevel = RequirementLevel.None;
    Form.GetField("address1_city").RequirementLevel = RequirementLevel.None;
    Form.GetField("address1_postalcode").RequirementLevel = RequirementLevel.None;
}

Field validation

This script will validate two fields based on the value of another field.

if (((Picklist)Form.GetValue("address1_shippingmethodcode")).Value == 5)
{
    IField city = Form.GetField("address1_city");
    IField postal = Form.GetField("address1_postalcode");

    if (string.IsNullOrEmpty((string)Form.GetValue("address1_city")) || string.IsNullOrEmpty((string)Form.GetValue("address1_postalcode")))
        throw new ApplicationException("Either the postalcode or city is required for the selected shipping method");
}

Read-only field

This script can be placed in the "OnLoad" handler. It will disable a field for existing records.

if (!Form.IsNewRecord)
{
  Form.GetField("name").IsReadOnly = true;
}

ScrewTurn Wiki version 3.0.4.560. This Wiki contains 108 pages.