> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Retrieve a sale

> How to retrieve a sale with CRMScript in SuperOffice

Whether you're a sales rep who wants to see whether you have enough ongoing sales opportunities to reach their budget or a sales manager who wants to see how their team is performing, inspecting the pipeline provides valuable info.

<Tip>
  You can only retrieve sales for persons that are SuperOffice users [associates][1]. The signed-in user must also have permission to view those sales. Otherwise, an exception is thrown.
</Tip>

**To view basic info, use NSSale:**

```crmscript theme={null}
NSSaleAgent saleAgent;
NSSale sale = saleAgent.GetSale(1);
printLine(sale.GetSaleTypeName());
```

**To view (and possibly update) complex info, use NSSaleEntity:**

```crmscript! theme={null}
NSSaleAgent saleAgent;
NSSaleEntity sale = saleAgent.GetSaleEntity(1);
printLine(sale.GetSaleType().GetValue());
```

## NSSale\[] GetSalesByDate(DateTime fromDate, DateTime toDate, Integer amountLimit, Integer status)

Fetch all sales within a time period. Optionally limit the result by amount and/or status.

* `amountLimit`: amount in local currency OR **-1** to ignore filter
* `status`: 1-4 (open,sold,lost,stalled) OR **0** to ignore filter

```crmscript! theme={null}
DateTime start;
start.addMonth(-6);
DateTime end;

NSSaleAgent saleAgent;
NSSale[] saleList = saleAgent.GetSalesByDate(start, end,-1,0);

for(Integer i = 0; i < saleList.length(); i++) {
  print(saleList[i].GetTitle() + "\t ID: " + saleList[i].GetSaleId().toString() + "\t amount: " + saleList[i].GetAmount().toString(1));
}
```

## NSSale\[] GetOpenSalesForContact(Integer contactId)

```crmscript theme={null}
NSSaleAgent saleAgent;
NSSale[] saleList = saleAgent.GetOpenSalesForContact(1);
```

## NSSale\[] GetUpcomingSales(Integer weightedAmountLimit, Integer count)

Fetches all open sales (in descending order). Optionally limit the result by a weighted amount and/or count. Set either filter to **-1** top ignore it.

Weighting is based on the probability that the sale will be closed (amount \* probability).

```crmscript theme={null}
NSSaleAgent saleAgent;
NSSale[] saleList = saleAgent.GetUpcomingSales(-1,-1);
```

## Statistics

### NSSaleSummary GetSummaryByAssociate(Integer associateId, DateTime start, DateTime end)

This example fetches the number of sold, lost, and open sales for an associate since January 01, 2020.

```crmscript! theme={null}
DateTime start = String("2020-01-01").toDateTime();
DateTime end;

NSSaleAgent saleAgent;
NSSaleSummary summary = saleAgent.GetSummaryByAssociate(1, start, end);

printLine("Sold: " + summary.GetSold().toString() + "\tLost: " + summary.GetLost().toString() + "\tOpen: " + summary.GetOpen().toString());
```

### NSSaleSummary GetSummaryByContact(Integer contactId, DateTime start, DateTime end)

This example fetches the number of sales and the total amount for a company from the time it was registered until now.

```crmscript! theme={null}
Integer contactId = 1;

NSContactAgent contactAgent;
NSContact contact = contactAgent.GetContact(contactId);

DateTime start = contact.GetCreatedDate();
DateTime end;

NSSaleAgent saleAgent;
NSSaleSummary summary = saleAgent.GetSummaryByContact(contactId, start, end);

printLine("Sold: " + summary.GetSold().toString() + "\tTotal: " + summary.GetSoldTotalBaseCurrency().toString());
```

[1]: ../../../../contact/dev/index#associate


## Related topics

- [Retrieve quote info](/en/automation/crmscript/howto/quote/get.md)
- [Record a sale](/en/automation/crmscript/howto/sale/create.md)
- [How to link a sale to a follow-up (services)](/en/api/web-services/howto/sale/link-sale-to-appointment.md)
- [How to use ActivityArchive filters](/en/api/search/iarchiveagent/using-activityarchive-filters.md)
- [Products](/en/automation/crmscript/howto/quote/products.md)
- [Currency](/en/automation/crmscript/howto/sale/currency.md)
