# Add New Fields

### Overview

This guide walks you through the **end-to-end process** of introducing a new field (e.g., `landmark`) in the **CMS service module**, starting from backend model changes to data persistence and validations.

Adding a new field typically involves changes across multiple layers:

* Java models (domain classes)
* Validation and enrichment logic
* Row mapping from DB
* Persister and indexer configurations

This ensures the field is:

* Captured in incoming requests
* Validated or enriched if needed
* Persisted to the database
* Indexed for search
* Returned in query results

***

## &#x20;Steps to Add a New Field

{% stepper %}
{% step %}

### Add a field in the model

In `Service.java` (or the appropriate domain class):

```java
private String landmark;
```

{% endstep %}

{% step %}

### Add validation (optional)

In the `validateCreate()` method inside the Validator class:

```java
if (request.getLandmark() == null) {
    throw new CustomException("PGR.LANDMARK_REQUIRED", "Landmark is required");
}
```

{% endstep %}

{% step %}

### Enrich the Request (optional)

In `enrichCreateRequest()` method:

```java
if (request.getLandmark() == null) {
    request.setLandmark("Default");
}
```

{% endstep %}

{% step %}

### Map DB Result (RowMapper)

In `PGRRowMapper.java`:

```java
service.setLandmark(rs.getString("landmark"));
```

{% endstep %}

{% step %}

### Update Persister Configuration

In `persister.yml`, under `save-pgr-request` and `update-pgr-request` topics:

```yaml
- jsonPath: $.Service.landmark
  dbColumn: landmark
  type: STRING
```

👉 After updating, **restart the Persister service**.
{% endstep %}

{% step %}

### Update Persister Configuration

In `indexer.yml`, under `save-pgr-request` and `update-pgr-request` topics:

```yaml
- jsonPath: $.Service.landmark
  dbColumn: landmark
  type: STRING
```

👉 After updating, **restart the Indexer service**.
{% endstep %}

{% step %}

### Add to Search Query (Optional)

If you want to search/filter by `landmark`:

* Update the query in `PGRQueryBuilder.java`
* Add it to the parameter map
  {% endstep %}
  {% endstepper %}

***

### ✅ Done!

Your new field is now fully integrated into the CMS backend — from request to persistence.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digit.org/complaints-management/complaints-resolution-v2.10/deploy/customise/backend/add-new-fields.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
