Workflow (BRE) in Lending
Workflow (BRE) in Frappe Lending allows users to apply business rules during document transitions. It helps define controlled approval journeys where actions such as screening, underwriting, approval, rejection, eKYC triggers, or eSign triggers can be executed based on workflow states.
In Lending implementations, workflows are commonly used to manage loan journeys by moving documents through predefined stages and executing validation tasks during each transition.
Did You Know?
Workflow Transition Tasks allow Lending workflows to execute custom actions such as Server Scripts, Webhooks, or custom Python methods during state changes.
Loan Lead Workflow
The default Loan Lead workflow in Lending follows these stages:
| State | Description |
|---|---|
| Incoming | Initial stage when a loan lead is created. |
| Scrubbing | Data validation stage where lead information is checked for completeness. |
| Pre-Qualification | Initial eligibility checks are performed. |
| Pre-Qualified | Lead passes pre-qualification checks. |
| Qualified | Lead is approved for conversion into a loan application. |
| Rejected | Lead does not meet the required criteria. |
Workflow Transition Tasks
Transition Tasks are linked using the Transition Tasks field in each workflow transition. These tasks define actions that should execute when a document moves from one state to another.
Available Task Sources
- Webhook
- Server Script
- Custom methods defined in
hooks.pyusingworkflow_methods
Example hooks.py Configuration
workflow_methods = [
{
"name": "Your Task",
"method": "my_app.workflow_tasks.your_task_method"
}
]
After configuration, the defined method appears in Workflow Transition Tasks and can be selected as a workflow task.
Loan Lead Workflow Transitions
| Transition | Action |
|---|---|
| Incoming → Scrubbing | Run Basic Rules |
| Scrubbing → Pre-Qualification | Run Pre-Qualification Rules |
| Pre-Qualification → Pre-Qualified | Run Knockout Rules |
| Pre-Qualified → Qualified | Converted to Application |
Scrubbing Stage
Scrubbing is the data-readiness stage before eligibility checks. During this stage, the Loan Officer verifies that required applicant information is complete and accurate.
Typical validations include:
- Applicant name, mobile number, loan product, and loan amount availability.
- Date of Birth availability for Individual applicants.
- Validation of contact information.
This ensures that pre-qualification rules are executed only on reliable and complete data.
Example: Scrubbing to Pre-Qualification
During the Run Pre-Qualification Rules transition, a Server Script can validate basic eligibility requirements such as applicant age and mandatory fields.
Example Server Script
errors = []
if doc.doctype != "Loan Lead":
frappe.throw("This task is only valid for Loan Lead")
required_fields = {
"applicant_name": "Applicant Name",
"mobile_number": "Mobile Number",
"loan_product": "Loan Product",
"loan_amount": "Loan Amount",
}
for fieldname, label in required_fields.items():
if not doc.get(fieldname):
errors.append(f"{label} is required")
if doc.get("applicant_type") == "Individual":
if not doc.get("date_of_birth"):
errors.append("Date of Birth is required for Individual applicant")
else:
today = frappe.utils.getdate()
dob = frappe.utils.getdate(doc.get("date_of_birth"))
age = today.year - dob.year
doc.age = age
if age < 21 or age > 65:
errors.append("Applicant age must be between 21 and 65")
if errors:
frappe.throw("<br>".join(errors))
Configuring Workflow Transition Tasks
Create a Workflow Transition Task with the following configuration:
| Field | Value |
|---|---|
| Task | Server Script |
| Link | Pre-Qualification Validation Script |
| Enabled | Yes |
| Asynchronous | No |
Mapping Task to Workflow Transition
After creating the transition task, map it to the required workflow transition:
Scrubbing → Pre-Qualification → Transition Tasks = Loan Lead - Pre-Qualification Tasks
How Workflow Processing Works
| Step | Description |
|---|---|
| 1. Document State Change | User triggers a workflow transition. |
| 2. Execute Transition Tasks | Configured tasks such as Server Scripts or Webhooks are executed. |
| 3. Apply Business Rules | Validation rules determine whether the transition can proceed. |
| 4. Update Workflow State | If successful, the document moves to the next workflow stage. |
Use Cases
Workflow (BRE) in Lending can be used for:
- Automating loan approval journeys.
- Implementing borrower eligibility checks.
- Triggering external verification services.
- Managing underwriting and review stages.
- Executing custom business validations.
Best Practices
- Keep workflow states aligned with actual lending processes.
- Use Server Scripts for validation logic that depends on document data.
- Use asynchronous tasks only for operations that do not require immediate validation.
- Test workflow transitions before applying them to live loan journeys.
References
- Workflow: https://docs.frappe.io/erpnext/workflows
- Workflow Transition Tasks: https://docs.frappe.io/erpnext/workflow-transition-tasks