The latest rollup update introduced a new feature called Read Optimized Forms. This enables a read-only version of the entity forms that optimized for users that want to rapidly read data instead of editing them.
One of the pre-requisites in the current implementation is that the form should be devoid of all script customizations. If so, how would you work around a situation where the form requires values to be dynamically calculated.
One of the recommended approaches, as defined in the SDK, is to use a synchronous sandbox plugin running on the Retrieve message of the entity.
The following code snippet demonstrates this:
- protected void ExecuteDynamicCalculationPlugin(LocalPluginContext localContext)
- {
- if (localContext == null)
- throw new ArgumentNullException("localContext");
- //The OutputParameters property bag contains the result of the core operation.
- Entity outEntity = localContext.PluginExecutionContext.OutputParameters["BusinessEntity"] as Entity;
- //Ensure values are valid to perform calculation
- if (outEntity.Attributes.Contains("null_hours") &&
- outEntity.Attributes.Contains("null_days"))
- {
- int hours = (int)outEntity.Attributes["null_hours"];
- int days = (int)outEntity.Attributes["null_days"];
- outEntity.Attributes["null_hours"] = hours * days;
- }
- }
And the plugin is registered as PostOutsideTransaction on the Retrieve event of the entity with the assembly under Sandbox isolation. This approach would also work on Online solutions as well.
Please beware of long running calculations as they are now being done synchronously as opposed to being done asynchronously through JavaScript.
No comments:
Post a Comment