---
sourceDocument: Xanadu Customer Service Management
sourceDocumentLink: https://www.servicenow.com/docs/r/xanadu/customer-service-management

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu Customer Service Management

ft:clusterId :

    - csm

bundleId :

    - csm

workflow :

    - Customer and Industry


---

# Get Opportunities for Account Id custom action

# Get Opportunities for Account Id custom action {#ariaid-title1}

* Release version: Xanadu
* 
* Updated January 30, 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

The Get Opportunities for Account Id action retrieves
opportunity records for the specific Salesforce account. This action is invoked when the agent
views a Salesforce opportunity available for the customer account based on the Salesforce
account associated with it.
This action is similar to the Get All Opportunities action.

## Action inputs {#csm-account-opportunities-action__section_cz2_m2z_53b}

In addition to the maximum number of records to be returned by the query, this action also
takes a Salesforce Account Id as input to be used as a query parameter. The value of this
parameter is provided by the relationship that links the customer account and the Salesforce
opportunity through the associated Salesforce Account Id. For more information, see [Create defined related
lists](https://www.servicenow.com/docs/7vQoor8yUMbIqXsHwLZApw "The Get Opportunities for Account Id action retrieves opportunity records for the specific Salesforce account. This action is invoked when the agent views a Salesforce opportunity available for the customer account based on the Salesforce account associated with it.").

The specific relationship needed for the reference example is also described in the [Using a related list to create the connection between the Customer Account and Salesforce
Opportunities](https://www.servicenow.com/docs/wKzza4b0~7oy4jbQB_RTsA "Use a related list to establish the connection between the Customer Account table that holds the Salesforce Account Id and the Salesforce Opportunity remote table that holds the same Salesforce Account Id.") topic.

The Salesforce Account Id action input parameter has no default value.


Action Outline with Inputs: Pre Processing script, REST step, Post Processing script. Action Input showing Label, Name, Type, and a toggle for Mandatory.

## Pre-processing step {#csm-account-opportunities-action__section_hrw_m2z_53b}

The pre-processing script step takes the action input as its own.

The Pre-Processing step script creates a SELECT query similar to the one created for the Get All Opportunities action with the addition of the check against the Salesforce Account Id.  

    (function execute(inputs, outputs) {
      
      outputs.query = "query/?q=SELECT+Name,Id,AccountId,CloseDate,Amount," +
                      "StageName,Probability,Type+FROM+Opportunity"         +
                      
                      "+WHERE+AccountId='" + inputs.salesforce_account_id + "

                      "+LIMIT+" + inputs.max_number_of_opportunity_records; 
      
    })(inputs, outputs);

The pre-processing output is a query, similar to the Get All Opportunities action.

## REST step, post-processing step, and action outputs {#csm-account-opportunities-action__section_j3b_n2z_53b}

These steps and outputs are the same as for the Get All Opportunities action.

