13. Adding Business Rules to the Solution
The following exercise will demonstrate how to create business rules based on different use cases.
Adding a Rule to Get the FICO Score
- Navigate to Application Studio (1) → DCM Training (2) solution.
- Navigate to Business Rules (1) > Rules (2)
- Filter the list by the Name action (3), and open the sample rule QA_actionNqFn (4)
- Click on the Clone button.
- Name the rule as CUST_TRN_getCreditScoreFn and click on the Clone button.
- We need to remove some Tags that we will not need for this rule and keep only cust and Common Event, as in the right image.
In the Code Body section, Copy and Paste the following code from the file CUST_TRN_getCreditScoreFn.sql located in the practice folder. (CUST_TRN_getCreditScoreFn.sql)
/* Last Updated SEP 27, 2021 Rule Name CUST_TRN_getCreditScoreFn Tags cust Template Type Default Rule Usage General Description GBank - Generate Random Credit Score and Update Auto Loan Application. Rule Type SQL Non Query Rule must be deployed to Procedure/Function Encoder Default Sample of simple rule that deployed as NonQuery SQL Function. Used by auto-tests (UCode could be defined in Input parameter). Input: - CaseId, Number (Case.Id) - TaskId, Number (Task.Id) - ProcedureId, Number (Procedure.Id) - Input, Text Area (collection of passed parameters in XML format) - InData, Text Area (custom user input data in XML format) Output - ValidationResult, Integer (0 = don't allow, 1 = allow) - ErrorMessage, Text Area - ErrorCode, Number - OutData, Text Area (custom user output data in XML format) See results in: 1. Case history 2. Task history 3. Setup -> Monitoring -> System Monitor */ DECLARE v_caseId NUMBER; v_taskId NUMBER; v_procedureId NUMBER; v_ErrorCode NUMBER; v_ErrorMessage NCLOB; v_validationresult NUMBER; v_input NCLOB; v_InData NCLOB; v_outData NCLOB; v_res NUMBER; v_logId NUMBER; v_UCode NVARCHAR2(255); BEGIN --INPUT v_caseId := :CaseId; v_taskId := :TaskId; v_procedureId := :ProcedureId; v_input := :Input; v_InData := :InData; --INIT v_outData := NULL; v_ErrorCode := 0; v_ErrorMessage := NULL; v_validationresult := 1; --valid by default --CALL LOG RULE p_executeImmediateSql('DECLARE v_res INT; BEGIN v_res := f_DAF_logEventFn(INPUT => ''' || v_input || '''); END;'); -- GENERATE RANDOM SCORE begin select TRUNC(DBMS_RANDOM.VALUE(550, 850)) into v_res from dual; exception WHEN NO_DATA_FOUND THEN v_res := 777; end; -- UPDATE CREDIT SCORE IN MDM TABLE begin UPDATE TBL_CDM_AUTO_LOAN SET COL_FICO = v_res WHERE COL_AUTO_LOANCASE = V_CASEID; v_outData := 'FICO Score Updated to ' || V_RES || ' in Case #' || V_CASEID; exception WHEN OTHERS THEN v_ErrorMessage := '[CUST_TRN_getCreditScoreFn] Error Updating FICO Score to ' || v_res || ' in Case #' || v_caseId; end; --WRITE HISTORY AND PROCESS ERRORS v_res := f_HIST_createHistoryFn( AdditionalInfo=> 'Rule : CUST_TRN_getCreditScoreFn', IsSystem => 0, Message => v_outData, MessageCode => 'CaseUpdated', TargetID => v_CaseId, TargetType => 'CASE' ); :ErrorCode := v_ErrorCode; :ErrorMessage := v_ErrorMessage; :validationResult := v_validationresult; :OUTDATA := v_outData; END;JS
Validate that the names of the table and columns highlighted corresponded to your Auto Loan MDM model:
UPDATE TBL_CDM_AUTO_LOAN SET COL_FICO = v_res WHERE COL_AUTO_LOANCASE = v_CaseId;SQL
Save the rule. You will see the rule summary after saving.
Our next step is to debug our new rule and validate that is working correctly. To do that, we need a Case ID for a given Case.
Navigate to Case Management → Search Cases
Make visible the column ID. In the image, you can see the number 2 for CASE-2021-2, Use the values in the column ID to debug the rule.
Go back to the Application Studio.
In the General tab click on the Debug button to test our new rule.
Using any Case ID (1) identified in the previous step execute the rule (Run button).
If there are no errors in the code of the rule you will see the successful result in the Rule Result In the below screen is
“OUTDATA":"FICO Score Updated to 554 in Case #2"(2)
You can check the new (random) FICO score (3) in the Case Info tab (2) for Case #2 (1)
Check the record inserted in the journal of the Case under the History tab (1) and check the result of the rule expanding the comments by clicking the Plus (+) button.
Close the Debug Rule window.
Save your rule definition.
Close the Edit Rule window.
As with any change made to AppBase, we must do a deployment of the changes. Navigate to Deployment Management > Deploy (this process could take 1-5 mins).
Using Rules in the Milestone Diagram
- Navigate to Setup (1) → Case Setup (2) → Case Types (3)
- Open the Auto Loan Milestone Diagram (4)
- From Basic Events in the left panel, drag & drop an Execute Rule (1) to the New milestone (2)
- In the Right panel, insert ‘Get FICO Score’ for the Name(3). Select ‘After’ for Event Moment(4) and select CUST_TRN_getCreditScoreFn in the Rule dropbox (5)
- Save the changes to the milestone.
To test the automatic execution of the rule when creating a case in status 'New'
- Navigate to Case Management and create a new case and see if the FICO Score is populated.
- Check the record inserted in the journal of the Case under the History tab (1) and check the result of the rule expanding the comments by clicking the plus button.
Congratulations! You have added a new business rule to the solution.
14. Milestone Diagram Configuration