Image CWR Mobility Wiki
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]


Edit

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

Edit

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.

Edit

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);
}

Edit

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.

Edit

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");
}

Edit

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;
}

Edit

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");
}

Edit

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 2.0.35. This Wiki contains 64 pages.