> ## 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.

# Script-based selections

Script-based selections give you the possibilities above the standard selection functionality. You may for instance use a SearchEngine to populate your search results.

## The structure of a script-based selection

When you create a new selection you need to choose a **Source Table**. The IDs returned from the method `getIds` are assumed to be of this table. When you have chosen the Source Table and pressed **Continue**, the next screen displays the bare-bone of the selection.

```crmscript theme={null}
#setLanguageLevel 2;

Integer execute()
{
  Integer count = 0;
  return count;
}

Integer[] getIds()
{
  Integer[] ids;
  return ids;
}
```

The script consists of 2 functions: `execute` and `getIds`. Place your search engine code in the `execute` function, and the code to retrieve the IDs in the `getIds` function.

## Example

```crmscript theme={null}
#setLanguageLevel 2;
// Retrieve all Companies that begin with SuperOffice.

Integer[] ids;
Integer execute()
{
  Integer count = 0;
  SearchEngine se;
  se.addField("contact.contact_id");
  se.addCriteria("contact.name", "OperatorBeginsWith", "SuperOffice", "OperatorAnd", 0);
  for (se.select(); !se.eof(); se.next())
  {
     ids.pushBack(se.getField(0).toInteger());
  }

  return ids.length();
}

Integer[] getIds()
{
  return ids;
}
```

A selection may be accessed using an URL in the form of:

`domain/scripts/ticket.exe?action=searchTable&table=<person>&selectionIncludeId=<incId>`

Replace `<person>` and `<incId>` with the table in question and the `includeId` of the selection.


## Related topics

- [Working with tiles](/en/dashboard/learn/working-with-tiles.md)
- [Flow control - split](/en/marketing/flows/learn/split.md)
- [Selection](/en/search-options/selection/learn/index.md)
- [NSSelectionAgent](/en/automation/crmscript/reference/CRMScript.NetServer.NSSelectionAgent.md)
- [NSSelectionEntity](/en/automation/crmscript/reference/CRMScript.NetServer.NSSelectionEntity.md)
