---
sourceDocument: 호주 고객 서비스 관리
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ko-KR/customer-service-management

 Release :

    - australia

ft:locale :

    - ko-KR

ft:publication_title :

    - 호주 고객 서비스 관리

ft:clusterId :

    - csm

bundleId :

    - csm

workflow :

    - Customer and Industry


---

# 기회 테이블을 쿼리하는 예시 스크립트

# 기회 테이블을 쿼리하는 예시 스크립트 {#csm-opportunity-table-script___Ref16694770}

* 릴리스 버전: Australia
* 
* 업데이트 날짜 2026년 03월 12일
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 소요 시간: 5분

이 예시 스크립트는 모든 기회 가져오기, 계정 ID에 대한 기회 가져오기 및 기회 세부 정보 가져오기 사용자 지정 작업을 사용하여 기회 테이블을 쿼리합니다.  
예시 스크립트는 다음 세 부분으로 구성되어 있습니다.

1. 첫 번째 부분에서는 올바른 사용자 지정 작업을 선택하고 입력을 준비합니다.
2. 두 번째 부분에서는 작업을 호출합니다.
3. 세 번째 부분에서는 작업의 출력을 처리합니다.
{#csm-opportunity-table-script__ol_u1s_tyj_v3b}

## 스포크 작업 선택 및 입력 준비 {#csm-opportunity-table-script__section_select_spoke_actions}

이 스크립트 섹션에서는 Salesforce 애플리케이션에서 기회를 가져올 준비가 된 세 가지 사용자 지정 작업 중 하나를 선택합니다.

* 모든 기회 가져오기
* 계정 ID에 대한 기회 가져오기
* 기회 세부 정보 가져오기

{#csm-opportunity-table-script__ul_z1q_bzj_v3b} `v_query` 함수 인수에 포함된 매개변수에 따라 호출할 작업을 결정할 수 있습니다.  

    /****** Choose action and prepare action inputs *****/
    var action = null;
    var inputs = {};

    // look up opportunity by salesforce record id
    if (v_query.isGet()) {

      action = "get_opportunity_details";
      inputs.salesforce_opportunity_record_id = v_query.getSysId();
          

    // look up opportunities by salesforce account id
    } else if (v_query.getParameter("u_sf_account_id")) {

        if (v_query.getParameter("u_sf_account_id") == "undefined") {
          gs.addInfoMessage("Opportunities cannot be retrieved because " +
                            "this "Account does not have associated "    +
                            "Salesforce Account. Please contact System " +
                             "Administrator.");
          return;

        } else {
          action = "get_opportunities_for_account_id";
          inputs.salesforce_account_id = v_query.getParameter("u_sf_account_id");
        }

    // look up all opportunities
    } else {
      action = "get_all_opportunities";
    }

이 스크립트는 Salesforce 계정이 작업에 필요할 때 정의되지 않은 경우 정보 메시지를 구성합니다. 정의되지 않은 값은 [관련 목록을 사용하여 고객 계정과 Salesforce 기회 간 연결 만들기](https://servicenow-prod.fluidtopics.net/exQIc~_OtHDHg5Amofekkw "관련 목록을 사용하여 고객 계정 테이블을 Salesforce 계정 ID와 연결하고 Salesforce , 기회 원격 테이블을 동일한 계정 ID와 연결합니다.")에 설명된 관계에서 비롯됩니다.

Salesforce 계정이 정의되어 있지 않으면 이 경우 쿼리할 것이 없으며 함수는 스포크 작업을 호출하지 않고 반환됩니다.

## 스포크 작업 호출 {#csm-opportunity-table-script__section_ed2_pzj_v3b}

이 스크립트 섹션에서는 Salesforce 스포크 이름과 선택한 작업을 사용하여 작업을 호출하고 호출의 출력을 저장합니다.  

    /***** Call action *****/
    var outputs =
            sn_fd.FlowAPI.executeAction("sn_salesforce_spok." + action, inputs);

## 작업 출력 처리 중 {#csm-opportunity-table-script__section_pqr_szj_v3b}

스크립트의 이 섹션에서는 오류 검사로 시작하는 출력을 처리합니다.  

    /***** Process action outputs *****/
    if (outputs.status != "Success") {
    throw new Error(outputs.error_message);
    }

쿼리가 오류를 반환하지 않으면 스크립트가 반환된 기록을 처리하여 원격 테이블에 행으로 추가해야 합니다. Salesforce 기회 필드를 원격 테이블 열에 매핑합니다.  

    var opportunities = outputs.opportunities.data;

     for (var i = 0; i < opportunities.length; i++) {
      var opportunity = opportunities[i];
      v_table.addRow({
        "u_sf_amount": opportunity.Amount,
        "u_sf_close_date": opportunity.CloseDate,
        "u_sf_name": opportunity.Name,
        "u_sf_probability": opportunity.Probability + "%",
        "u_sf_account_id": opportunity.AccountId,
        "u_sf_stage": opportunity.StageName,
        "u_sf_type": opportunity.Type,
        "sys_id": opportunity.Id,
      });
    }

Salesforce 기회 기록 Id가 원격 테이블 sys_id에 할당됩니다. 이렇게 하면 원격 테이블의 목록과 양식이 제대로 작동하는지, 다음에 원격 테이블 스크립트가 호출될 때 `v_query.getSysId()` 를 사용하여 기록 ID를 추출할 수 있는지 확인할 수 있습니다.

그런 다음 쿼리에 의해 통과되면 정보 메시지를 표시합니다.  

    if (outputs.info_message) {
      gs.addInfoMessage(outputs.info_message);
    }

## 원격 테이블 스크립트 섹션을 함께 배치 {#csm-opportunity-table-script__section_z11_k1k_v3b}

스크립트의 세 개 섹션은 try-catch 블록에 포함되어 오류 처리를 제공합니다.  

    (function executeQuery(v_table, v_query) {

      try {

        // place code here from: <Selecting a spoke action and preparing the inputs>

        // place code here from: <Calling the spoke action>

        // place code here from: <Processing the action output>  	
            
      } catch (error) {
        gs.addErrorMessage("Error retrieving  Salesforce Opportunities. " +
                           "Please contact System Administrator.");
        gs.addErrorMessage("System Error: " + error.message);
      }

    })(v_table, v_query);


