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

# Samples

> Sample code for working with requests in CRMScript.

## List available categories

```crmscript! theme={null}
SearchEngine se;
se.addField("ej_category.name");
printLine(se.executeTextTable());
```

## List available priorities

```crmscript! theme={null}
SearchEngine se;
se.addField("ej_priority.name");
printLine(se.executeTextTable());
```

## Find requests

### Search for a ticket with a given tag

Tagging is a powerful tool for organizing and finding requests in SuperOffice Service.

```crmscript! theme={null}
SearchEngine se;
se.addFields("ticket", "id,title");
se.addCriteria("ticket.tags", "in", "1,2");
printLine(se.executeTextTable());
```

<Tip>
  List tags by their ID as a comma-separated string.
</Tip>

### List all tickets with a given status

```crmscript! theme={null}
SearchEngine se;
se.addFields("ticket", "id,title,cust_id.contact_id.associate_id");
se.addCriteria("ticket.status", "OperatorEquals", "1");
printLine(se.executeTextTable());
```

This snippet lists all **active** tickets. Change the last argument to `addCriteria()` to filter on other statuses.

## Find people

### Find "Our contact" on the company for the customer connected to the ticket

There is not a direct route from a ticket to an associate. You need to step through the tables in the following order using the foreign keys:

* Ticket (cust\_id)
* Person (contact\_id)
* Contact (associate\_id)
* Associate

```crmscript theme={null}
SearchEngine se;
se.addField("ticket.cust_id.contact_id.associate_id");
se.addCriteria("ticket.id", "OperatorEquals", "1");
se.execute();
```

This snippet fetches the associate ID of "Our contact" form ticket 1.

## Postpone tickets

Sometimes you need to put tickets on the back-burner.

```crmscript theme={null}
DateTime now = getCurrentDateTime();

Ticket t;
t.load(3);
t.setValue("status", "3");
t.setValue("lastChanged", now.toString());
t.setValue("dbiLastModified", now.toString());

Message m;
m.setValue("ticketId", t.getValue("id"));
m.setValue("createdAt", t.getValue("lastChanged"));
m.setValue("createdBy", t.getValue("ownedBy"));
m.setValue("slevel", "1");
m.setValue("body", "Expecting fix in next patch");
m.save();

t.setValue("activate", now.moveToMonthEnd().toString());
t.save();
t.notifyEmail(5);
```


## Related topics

- [Samples](/en/automation/crmscript/howto/sale/samples.md)
- [TicketStaticSelectionV2](/en/api/archive-providers/reference/ticketstaticselectionv2.md)
- [TicketTransferredNotification](/en/api/archive-providers/reference/tickettransferrednotification.md)
- [TimeZones](/en/api/archive-providers/reference/timezones.md)
