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

# Set/clear interest on company

> How to update interests for a company with SuperOffice CRMScript.

You can search for an [interest][1] and then set the interest to true or false. Here, we use a CRMScript.

## Code

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

Integer contactId = 6;
Integer interestToSelectId = 5;

NSContactAgent contactAgent;
NSContactEntity contactEntity = contactAgent.GetContactEntity(contactId);
NSSelectableMDOListItem[] contactInterests = contactEntity.GetInterests();

for (Integer i = 0; i < contactInterests.length(); i++)
{
  NSSelectableMDOListItem interestsOrHeadings = contactInterests[i];

  if (interestsOrHeadings.GetId() == interestToSelectId)
  {
    interestsOrHeadings.SetSelected(true);
    printLine("InterestId " + interestToSelectId.toString() + " with name: " + interestsOrHeadings.GetName() + " found on root level");
  }

  NSSelectableMDOListItem[] childItems = interestsOrHeadings.GetChildItems();
  for (Integer y = 0; y < childItems.length(); y++)
  {
    if (childItems[y].GetId() == interestToSelectId)
    {
      childItems[y].SetSelected(true);
      printLine("InterestId " + interestToSelectId.toString() + " with name: " + childItems[y].GetName() + " found as a childInterest under heading: " + interestsOrHeadings.GetName());
    }
  }
  interestsOrHeadings.SetChildItems(childItems);
}

contactEntity.SetInterests(contactInterests);
contactEntity = contactAgent.SaveContactEntity(contactEntity);
```

## Walk-through

In SuperOffice, you can define an interest both with and without a heading (an interest can also exist under multiple headings). Each interest has its unique ID, which we in the example above used to set a specific interestId to true. It doesn't matter if you move an interest to a different heading, as the unique ID stays consistent.

First, we need to loop the `NSSelectableMDOListItem[]` we get back from the `GetInterests()` method:

```crmscript theme={null}
NSContactAgent contactAgent;
NSContactEntity contactEntity = contactAgent.GetContactEntity(contactId);
NSSelectableMDOListItem[] contactInterests = contactEntity.GetInterests();
```

In this array, we can put interests/items on the root, without a heading, or we can get an item for the heading, which then contains child items for the actual interests (nested).

This code block checks the root:

```crmscript theme={null}
if (interestsOrHeadings.GetId() == interestToSelectId)
{
  interestsOrHeadings.SetSelected(true);
  printLine("InterestId " + interestToSelectId.toString() + " with name: " + interestsOrHeadings.GetName() + " found on root level");
}
```

Here, we get the child items for the item/heading and check each of the nested items:

```crmscript theme={null}
NSSelectableMDOListItem[] childItems = interestsOrHeadings.GetChildItems();
for (Integer y = 0; y < childItems.length(); y++)
{
  if (childItems[y].GetId() == interestToSelectId)
  {
    childItems[y].SetSelected(true);
    printLine("InterestId " + interestToSelectId.toString() + " with name: " + childItems[y].GetName() + " found as a childInterest under heading: " + interestsOrHeadings.GetName());
  }
}
interestsOrHeadings.SetChildItems(childItems);
```

<Note>
  We also need to `SetChildItems` back into the `interestOrHeadings` array.
</Note>

[1]: ./index


## Related topics

- [Set/clear interest on contact](/en/automation/crmscript/howto/interests/contact-interests.md)
- [NSMailMergeSettings](/en/automation/crmscript/reference/CRMScript.NetServer.NSMailMergeSettings.md)
- [Interests](/en/automation/crmscript/howto/interests/index.md)
- [Company](/en/company/learn/index.md)
- [Person table](/en/api/bulk-operations/bulk-update/reference/person-table.md)
- [Companies](/en/mobile/company/index.md)
