Skip to main content
Skip table of contents

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

  1. Navigate to Application Studio (1) → DCM Training (2) solution.
  2. Navigate to Business Rules (1) > Rules (2)
  3. Filter the list by the Name action (3), and open the sample rule QA_actionNqFn (4)

  4. Click on the Clone button.

  5. Name the rule as CUST_TRN_getCreditScoreFn and click on the Clone button.

  6. 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.
  7. 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)

    CUST_TRN_getCreditScoreFn Code

    JS
    /*
      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;

  8. Validate that the names of the table and columns highlighted corresponded to your Auto Loan MDM model:

    SQL
    UPDATE TBL_CDM_AUTO_LOAN
    SET COL_FICO = v_res
    WHERE COL_AUTO_LOANCASE = v_CaseId;
  9. 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.

  10. Navigate to Case Management → Search Cases

  11. 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.

  12. Go back to the Application Studio.

  13. In the General tab click on the Debug button to test our new rule.

  14. 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)

  15. You can check the new (random) FICO score (3) in the Case Info tab (2) for Case #2 (1)

  16. 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.

  17. Close the Debug Rule window.

  18. Save your rule definition.

  19. 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

  1. Navigate to Setup (1) → Case Setup (2) → Case Types (3)
  2. Open the Auto Loan Milestone Diagram (4)


  3. From Basic Events in the left panel, drag & drop an Execute Rule (1) to the New milestone (2)
  4. 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)
  5. Save the changes to the milestone.
    To test the automatic execution of the rule when creating a case in status 'New'
  6. Navigate to Case Management and create a new case and see if the FICO Score is populated.
  7. 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.

Next Steps

14. Milestone Diagram Configuration


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.