# 비즈니스 규칙 (Business Rule)

{% hint style="warning" %}
버전 1.37부터 ‘**데이터소스(Data Source)**’가 ‘**비즈니스 규칙(Business Rule)**’으로 명칭이 변경되었습니다.
{% endhint %}

조회 또는 라인 아이템과 **관련된 개체**나 **외부 API 서버에서 필요한 데이터를 조회**하거나, **복잡한 로직**이나 계산식을 사용해 처리된 **데이터를 함께 표시**하거나 **일부 필드에 기본값**으로 설정할 때 사용합니다.

### 비즈니스 규칙 설정

**조회 선택기 설정(Setup Lookup Selector)** 또는 **라인 아이템 편집기 설정(Setup Line Item Editor)** 단계로 이동하면 하단에 비즈니스 규칙을 설정할 수 있는 레이아웃이 나타납니다.

<figure><img src="/files/rHuRufUHyj37SXpwIzHn" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**라인 아이템 편집기**는 **평가 이벤트(Evaluation Event)를 필수**로 설정해주어야 합니다.\
평가 이벤트(Evaluation Event)는 아래와 같이 제공됩니다.

* **초기화 시(On Initialization):** 라인 아이템 레코드가 새로 추가되었을 때 실행됩니다.
* **로딩 시(On Loading):** 라인 아이템 화면이 로드될 때마다 실행됩니다.
* **변경 시(On Change):** 라인 아이템의 특정 필드가 변경될 때마다 실행됩니다.
* **저장 전(Before Save):** 라인 아이템 레코드들이 저장되기 전 실행됩니다.\\

  <figure><img src="/files/9ynITZwrivueULQVShtt" alt=""><figcaption></figcaption></figure>

{% endhint %}

### 비즈니스 규칙 유형

<figure><img src="/files/VONymC5ptoijQbqWYskt" alt=""><figcaption></figcaption></figure>

#### [관련 객체에서 데이터 가져오기](/ko/smallbuilder-line-items/builder/datasource/object.md)

**단순히 관련된 개체를 조회**하려는 경우, 데이터소스 기본 설정을 사용해보세요. 조회 또는 라인 아이템과 관련된 개체를 선택하고, 데이터소스를 통해 가져온 개체의 필드 값을 조회 또는 라인 아이템 필드에 매핑할 수 있습니다.

#### [Apex 클래스를 사용하여 데이터 가져오기](/ko/smallbuilder-line-items/builder/datasource/apex.md)

**외부 API 서버에서 데이터를 조회**하거나, 데이터 조회 및 결합 시 **복잡한 로직이 요구**되는 경우에 사용됩니다. 데이터소스 고급을 설정하려면 **Apex 클래스를 작성**해야 합니다. Apex 클래스를 사용해 구현하므로, 데이터소스 기본보다 데이터를 더 자유롭게 가져올 수 있다는 장점이 있습니다.

### 비즈니스 규칙 실행 순서

비즈니스 규칙은 **관련 객체를 사용하는 규칙(Basic)**&#xC774; 먼저 실행된 후, **Apex 클래스를 사용하는 규칙(Advanced)**&#xC774; 실행됩니다.

{% stepper %}
{% step %}
**관련 객체를 이용한 규칙 (Basic)**

**추가된 순서대로 실행**됩니다.
{% endstep %}

{% step %}
**Apex 클래스를 사용한 규칙 (Advanced)**

일반적으로 추가된 순서대로 실행되지만, **실행 순서는 보장되지 않을 수 있습니다.**
{% endstep %}
{% endstepper %}


---

# 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://help.smallbuilder.com/ko/smallbuilder-line-items/builder/datasource.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.
