10
.NET Business Rules for Microsoft Dynamics CRM Roman Savran

Business Rules

Embed Size (px)

DESCRIPTION

Business Rules

Citation preview

Page 1: Business Rules

.NET Business Rules for Microsoft Dynamics CRMRoman Savran

Page 2: Business Rules

How it usually works

• User opens new form, or form of existing record

• User fills data in fields

User works with UI form

• Validate user data• Calculate fields• Specify what fields are

required or not• Filter data user can

see or select

Custom JavaScript (UI rules) Logic

apply • User press save button (or any other that submit changes) or

• External application submits data via WebServices

User/WebService Submits Data

• Validate user input• Calculate fields• Make some changes in

system based on submitted data

Custom .NET/Workflow

logic apply

Business Logic Business Logic

Page 3: Business Rules

What to choose?

Pros• Instant feedback• Allow to limit user

actions

Cons• Do not guarantee

data consistency and input quality

Pros• Guarantee data

consistency

Cons• Feedback only after

saving data• Can only say

“Ooops!” on wrong input

UI lo

gic

Serv

er sid

e lo

gic

Page 4: Business Rules

Why I wanted to change something?

• I hate coding business logic in JavaScript• I want to have same code for UI and Server side using pros

of each scenario• I don’t want to chose how to implement functionality, in

JavaScript or Plugins, just want my code work in both cases

• I want to place patterns I use in pre-developed code so I don’t need to think about them every time

Page 5: Business Rules

Rule types

• Calculate some fields based on other fields valueCalculation

• Validates user inputValidation

• Filters fields values Filtering• Defines what fields can be changed by User and what

notEnable

• Defines what fields are required for the formRequired

• Defines what fields are visible and what are notVisible

• Makes post-processing of data changesProcessing

• Filters data user see in the systemDataFiltering

Page 6: Business Rules

Rules applicationRule\Place UI Server-side

Calculation Set calculated value in field Set calculated value in field

Validation Shows user notification near wrong field

Throws exception when saving data

Filtering Allows User to select only filtered data

Throws exception if data is not filtered properly

Enable Enables User to enter data in field

N/A

Required Set field as Required Throws exception if required field is not set

Visible Show/Hide field to user N/A

Processing N/A Run business logic after data saved

DataFiltering Disable field on UI form Remove secured data from output

Page 7: Business Rules

How rules apply on UI

• JavaScript library independent from business logic• Just add OnLoad event to form• OnChange events are generates automatically based on rules

description• When form loads or User changes some fields, rules are executed• Javascript calls action that returns rules execution result and apply this

results to form• Works independently of fields available on form

Page 8: Business Rules

• General plugin that attached to:• Entity create/update/delete event (Pre + Post)• Entity setstate/setstatedynamicentity event (Pre + Post)

• Plugin uses reflection to define what rules to execute and executes them when needed

How rules apply on Server-side

Page 9: Business Rules

Demo

Roman Savran

Page 10: Business Rules

Contact