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

# Stakeholders

> Working with sale stakeholders in CRMScript.

<Note>
  This feature requires a **Sales Premium** license or the **Growth** plan.
</Note>

## Organizations as stakeholders

The `contact_id` is the ID of the organization and the `person_id` is 0.

<Note>
  We're working with the **contact** database table here. Not to be confused with the **company** table!
</Note>

### Look up a company based on its domain

```crmscript! theme={null}
Company c;
c.findFromDomain("superoffice.com");
print(c.getValue("name"));
```

### View company info

```crmscript! theme={null}
Integer stakeholderId = 1;
NSSaleAgent saleAgent;
NSSaleStakeholder stakeholder = saleAgent.GetSaleStakeholder(stakeholderId);

if (stakeholder.GetPersonId() != 0) {
  printLine("Name: " + stakeholder.GetContactName() + "\t Role: " + stakeholder.GetStakeholderRoleName());
}
```

Read more about [working with organizations][1].

## Individuals as stakeholders

The `contact_id` is the ID of the organization (as before) but the `person_id` is 0.

<Note>
  We're working with the **person** database table here. Not to be confused with the **contact** or **associate** tables!
</Note>

### Look up a person based their email address

```crmscript! theme={null}
Customer c;
printLine(c.findFromEmail("jean-luc@superoffice.com").toString());
```

### View person info

```crmscript! theme={null}
Integer stakeholderId = 2;
NSSaleAgent saleAgent;
NSSaleStakeholder stakeholder = saleAgent.GetSaleStakeholder(stakeholderId);

if (stakeholder.GetPersonId() != 0) {
  printLine(stakeholder.GetFirstname() + " " + stakeholder.GetLastname());
}
```

Read more about [working with persons][2].

## List all stakeholders of a sale

**Get from agent:**

```crmscript! theme={null}
Integer saleId = 4;
NSSaleAgent saleAgent;
NSSaleStakeholder[] stakeholderList = saleAgent.GetSaleStakeholders(saleId);

for(Integer i = 0; i < stakeholderList.length(); i++) {
  print(stakeholderList[i].GetSaleStakeholderId().toString() + "\t");
  printLine("Contact: " + stakeholderList[i].GetContactId().toString() + "\t Person: " + stakeholderList[i].GetPersonId().toString());
}
```

**Get from current sale:**

```crmscript theme={null}
NSSaleEntity sale;
NSSaleStakeholder[] stakeholderList = sale.GetSaleStakeholders();
```

## Create a stakeholder

```crmscript theme={null}
NSSaleStakeholder stakeholder = saleAgent.CreateDefaultSaleStakeholder();
stakeholder.SetContactId(1);
stakeholder.SetSaleId(4);
stakeholder.SetStakeholderRoleId(1);
stakeholder = saleAgent.SaveSaleStakeholder(stakeholder);
```

### List available roles

```crmscript! theme={null}
SearchEngine se;
se.addFields("StakeholderRole", "StakeholderRole_Id,name");
print(se.executeTextTable());
```

### Add new stakeholder to a sale

```crmscript theme={null}
NSSaleAgent saleAgent;
NSSaleEntity sale = saleAgent.GetSaleEntity(4);

// Pull up the stakeholder we just created
NSSaleStakeholder newStakeholder = saleAgent.GetSaleStakeholder(1);

NSSaleStakeholder[] stakeholderList = sale.GetSaleStakeholders();
stakeholderList.pushBack(newStakeholder);

sale.SetSaleStakeholders(stakeholderList);

sale = saleAgent.SaveSaleEntity(sale);
```

## Reference

### NSSaleStakeholder

| Field               | Get method             | Description                     |
| :------------------ | :--------------------- | :------------------------------ |
| salestakeholder\_id | GetSaleStakeholderId() | ID                              |
| stakeholderrole\_id | GetStakeholderRoleId() | Role                            |
| sale\_id            | GetSaleId()            | parent sale                     |
| contact\_id         | GetContactId()         | contact (person or org)         |
| person\_id          | GetPersonId()          | ID of person OR **0** if an org |

For a complete list of fields, see the [database reference][3].

[1]: ../company/index

[2]: ../contact/index

[3]: ../../../../database/tables/salestakeholder


## Related topics

- [Stakeholders](/en/sale/learn/stakeholders/index.md)
- [Add stakeholders](/en/sale/learn/stakeholders/create.md)
- [Edit or remove stakeholders](/en/sale/learn/stakeholders/edit.md)
- [Add Sale Stakeholders](/en/api/reference/restful/agent/sale_agent/add-sale-stakeholders.md)
- [Update Sale Stakeholders](/en/api/reference/restful/agent/sale_agent/update-sale-stakeholders.md)
