CWR Mobility Wiki
Navigation
Main Page
What's New
All Pages
Categories
Tags
1.2
4.0
4.1
4.1.0.10
4.1.0.9
4.2
4.2.0.0
4.2.0.1
4.2.0.5
BlackBerry
CRM 3.0
CRM 4.0
CRM Online
Default Sales Profile
FAQ
General
Guides
HOWTO
Installation
iPhone
Mobile Express
Private
Sample
SDK
Server
TODO
Windows Mobile
Other Links
CWR Mobility Website
CWR Mobility Blog
Language Selection
Quick Search
Advanced Search »
Back
History
CWR Mobile CRM 4.2 Scripting SDK Guide
{S:Draft} {S:AppliesToMobile|4.2} {toc} ===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. {BR} 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 [CWR42CustomControls|Custom Controls]. ===Interface=== {{{{<nowiki> 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); } </nowiki>}}}} ===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. {{{{<nowiki>string original = (string) Form.GetValue("address1_postalcode"); Match match = Regex.Match(original, @"(?<digits>[0-9]{4})\s+(?<letters>[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"); }</nowiki>}}}} ====Setting requirement level==== This script changes the requirement level of other fields when it is triggered in the "OnChange" method. {{{{<nowiki>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; }</nowiki>}}}} ====Field validation==== This script will validate two fields based on the value of another field. {{{{<nowiki>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"); }</nowiki>}}}} ====Read-only field==== This script can be placed in the "OnLoad" handler. It will disable a field for existing records. {{{{<nowiki>if (!Form.IsNewRecord) { Form.GetField("name").IsReadOnly = true; }</nowiki>}}}}
ScrewTurn Wiki
version 2.0.35. This Wiki contains 64 pages.