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

> How to update interests for a SuperOffice contact with 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 personId = 13;
Integer interestToSelectId = 5;

NSPersonAgent agent;
NSPersonEntity entity = agent.GetPersonEntity(personId);
NSSelectableMDOListItem[] interests = entity.GetInterests();

for (Integer i = 0; i < interests.length(); i++)
{
  NSSelectableMDOListItem interestsOrHeadings = interests[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);
}

entity.SetInterests(interests);
entity = agent.SavePersonEntity(entity);
```

## 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}
NSPersonAgent agent;
NSPersonEntity entity = agent.GetPersonEntity(personId);
NSSelectableMDOListItem[] interests = entity.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 company](/en/automation/crmscript/howto/interests/company-interests.md)
- [How to set an interest on or off for a contact (services)](/en/api/web-services/howto/company/set-interest-on-off-services.md)
- [Contact table](/en/api/bulk-operations/bulk-update/reference/contact-table.md)
- [Interests](/en/automation/crmscript/howto/interests/index.md)
- [Person table](/en/api/bulk-operations/bulk-update/reference/person-table.md)
- [Update Interests](/en/api/reference/restful/agent/contact_agent/update-interests.md)
