Calculated fields are new to CRM 2015. Business Rules now also have a new Entity Level scope option. When it comes to simple decimal operations you can use either Business Rules at Entity Level scope or calculated fields. Obviously calculated fields, are much more powerful than business rules. There is one issue I experienced with business rules at entity level. The division operator currently does not seem to work properly.
This the business rule to perform the division.
When you save the record an error is displayed.
This is the actual error
The calculated field that performs the division works without any issue.
Interesting behaviours that I encountered below.
Scenario 1: Calculated field to divide two integers and the result of the operation is float e.g. : 5 / 2
Result: The result is rounded up to the closest int.
Scenario 2: Calculated field - Divide by zero
Result: No divide by zero exception. The result is blank.
Scenario 3: Calculated field of type text, with calculation using decimal fields.
Result: No error. Result of the operation is can be assigned to the string field.
Conclusion: If it can be done using calculated fields, do it that way, instead of Entity scope business rules, as calculated fields offer much more flexibility and functionality.
This the business rule to perform the division.
When you save the record an error is displayed.
This is the actual error
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Expression operator not supported for specified type.Detail: <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"> <ErrorCode>-2147220891</ErrorCode> <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"> <KeyValuePairOfstringanyType> <d2p1:key>OperationStatus</d2p1:key> <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value> </KeyValuePairOfstringanyType> <KeyValuePairOfstringanyType> <d2p1:key>SubErrorCode</d2p1:key> <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value> </KeyValuePairOfstringanyType> </ErrorDetails> <Message>Expression operator not supported for specified type.</Message> <Timestamp>2014-12-06T22:54:07.9005933Z</Timestamp> <InnerFault i:nil="true" /> <TraceText> [Microsoft.Crm.ObjectModel: Microsoft.Crm.ObjectModel.SyncWorkflowExecutionPlugin] [c3877360-9a7d-e411-80cf-e83935c2f340: ] Starting sync workflow 'Decimal Formula', Id: bc877360-9a7d-e411-80cf-e83935c2f340 Entering ConditionStep1_step: Sync workflow 'Decimal Formula' terminated with error 'Expression operator not supported for specified type.' </TraceText> </OrganizationServiceFault>
The calculated field that performs the division works without any issue.
Interesting behaviours that I encountered below.
Scenario 1: Calculated field to divide two integers and the result of the operation is float e.g. : 5 / 2
Result: The result is rounded up to the closest int.
Scenario 2: Calculated field - Divide by zero
Result: No divide by zero exception. The result is blank.
Scenario 3: Calculated field of type text, with calculation using decimal fields.
Result: No error. Result of the operation is can be assigned to the string field.
Conclusion: If it can be done using calculated fields, do it that way, instead of Entity scope business rules, as calculated fields offer much more flexibility and functionality.
No comments:
Post a Comment