Thursday, 10 October 2013

Parsing Whole Number value while Setting in MSCRM 2011

Int i;
if (Int32.TryParse(TextBox_Employees.Text, out i))
{
 mylead["numberofemployees"] = i;
}

Get selected Option Set value label in mscrm 2011 C#

                      RetrieveAttributeRequest request = new RetrieveAttributeRequest();
                       request.EntityLogicalName = targetEntity.LogicalName;
                       request.LogicalName = optionsetLogicalName;
                       request.RetrieveAsIfPublished = true;          

                      RetrieveAttributeResponse response = (RetrieveAttributeResponse)service.Execute(request);
                       PicklistAttributeMetadata picklist = (PicklistAttributeMetadata)response.AttributeMetadata;

                       var query = from option in picklist.OptionSet.Options
                                   where option.Value == int.Parse(Statusvalue.ToString())
                                   select option.Label.UserLocalizedLabel.Label;
                        SselectedOptionSetlLabel = query.FirstOrDefault().ToString();

Monday, 7 October 2013

Limitations for Business Rules in MSCRM 2013

Limitations for Business Rules
·         Business rules in this release are intended to address common actions. Compared to what a developer can do using form scripts, business rules have limitations. However, business rules are not intended to replace form scripts.
·         The primary limitation you may find compared to form scripts is that all conditions in the Business rules are evaluated using AND. All the conditions must be true before the actions will be applied. There is no support for OR or Else operators to provide for more complex logic. To apply OR in your conditions you need to create separate rules for each condition you want to test. This can be done efficiently by using the Save As option and creating separate rules for each condition you want to test.
·         Business rules run only when the form loads and when field values change. They do not run when a record is saved.
·         Business rules work only with fields. Form scripts can interact with other visible elements such as tabs and sections within the form
·         When you set a field value using a business rule, any OnChange event handlers for that field will not run. This is to reduce the potential for a circular reference which could lead to an infinite loop.
·         If a Business Rule references a field that is not present on a form, the rule will simply not run. There will be no error message.
·         Calling other javascript web resources in the system via the business rule editor is not possible.

·         There is no ability to connect to external data sources.

Business Rules in MSCRM 2013 (Notes)

Miscellaneous Topics
·         Business rules cannot be run across different entities. They have to be defined within the same entity.
·         By default, the business rules are always created in a deactivated/draft state and must be activated to start executing for the form.
·         If there are multiple business rules for a control, the rules will run in the order they were added to the system. The last modified business rule runs last.
·         If you try to delete an attribute that has an active associated business rules, an error is triggered:
            "Process Error"
·         Business Rules can run on the web client (all browsers), Outlook (online and offline), iPad and CRM for tablets. However, they can only be customized through the Web Client or Outlook (Online/connected mode).
·         A new privilege for “Activate Business rules” under the customization tab for security roles has been added. Without activating the business rule first, it will not be executed.
·         Business Rules are imported/exported with the entities that they are attached to. It is not possible to export or import just a collection of business rules.
·         If there are multiple solutions, business rules will be run in the order in which the solutions were imported and the latest installed solution’s rules will run last.
·         If you package a managed/unmanaged solution, the states of the Business rules will be transported as is into the target system:
1.       activated rules will be activated
2.       deactivated rules will be deactivated

·         There are no limits on number of actions that can be attached to the business rule. 

Bussiness Rule Configuration Actions in MSCRM 2013


Validate data and show error message rules

Data in fields (as values) can be validated and comparison can be made between different fields.
 If the action states throwing an error message, you can define the control that should display the message.


Show or Hide a field rules

 You can change whether the field is displayed in the form. The options are Show Field and Hide Field.
 These are applicable to only fields and not for tabs, sections or controls like web resources and iframes.
If you do not specify any conditions, this is similar to setting state by default.

Enable or disable field rules

The options are Lock and Unlock. When the field is locked, you will not be able to edit the value in the field.
 If you do not specify any conditions, this is similar to locking/unlocking the field by default.

Set field value rules

Choose the Field and Type. There are three types:

 Field

Use this type to set the value of one form field with the value of another field.
 Value

Use this type to set the value of a form field with a value you enter.
 Formula

This option only appears for numerical or date data types. It does not appear for fields that contain text. Use this type to set the value to the result of a simple calculation that may use either a value in another form field or a value you enter.
 If you do not specify any condition, this is similar to setting a default value for the field.

Set field requirement rules

 The options are Not Business Required and Business Required. There is no option to set this to business recommended.
If you do not specify any condition, this is similar to setting the default business requirement state.