Image CWR Mobility Wiki
This article applies to:
  • CWR Mobile CRM 4.1

This sample control allows the administrator the set default values for fields on new forms.

This controls loads the information from the Configuration and in the set defaults sets these values:
public void Configure(IFormContext context, string configurationXml)
{
    // Set the form context on which the control is located
    _formContext = context;

    // Load the Configuration Fields and Default Values into a dictionary.
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(configurationXml);

    XmlNodeList attributes = xmlDoc.SelectNodes("//Attribute");
    _defaultValues = new Dictionary(attributes.Count);

    foreach (XmlNode attribute in attributes)
    {
        _defaultValues.Add(attribute.Attributes["Name"].Value, attribute.FirstChild.InnerText);
    }
}
public void SetDefault()
{
    // When the form is loaded, we need to check if it is for a new record, or an existing record
    if (_formContext.ObjectId == null) // New record
    {
        // Fill all the field from the dictionairy with the default values
        foreach (string formField in _defaultValues.Keys)
        {
            _formContext.SetFieldValue(formField, _defaultValues[formField]);
        }
    }
}

Download: Set Defaults Source
This contains the source files and visual studio project for this control. You can build this project your self.

Download: Set Defaults Package
This is a precompiled package of the set defaults control. You can upload this to the CWR Mobile CRM server and configure it for use on any form.

ScrewTurn Wiki version 2.0.35. This Wiki contains 64 pages.