> For the complete documentation index, see [llms.txt](https://docs.holium.com/ballot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.holium.com/ballot/custom-actions/sample-code.md).

# Sample Code

## Get a booth owner

Within the `++ action` arm of your custom action handler, obtain booth information using the following hoon:

{% code overflow="wrap" %}

```hoon
::  note that store and context are both provided in the outer/parent core in
::    which the 'on' arm resides
=/  booth  (~(get by booths.store) booth-key.context)
::  the call above will return an object of type (unit json)
::    you'll want to ensure this is not null, and if not, grab the inner
::    json object using `need`
=/  booth  ?~(booth ~ (need booth))
::  at this point, booth will either be null or a valid json object. however,
::  before you can work with the booth as json, you'll need to verify it's a valid
::  json type using the following code
=/  booth  ?:(?=([%o *] booth) p.booth ~)
::  here, booth will be a (map @t json) instance or null (default of map). from this
::   point forward you can, manipulate/query the booth data using stdlib map functions
::  for example, if you wanted to get the booth owner:
=/  booth-owner  (~(get by booth) 'owner')
=/  booth-owner  ?~(booth-owner '' (so:dejs:format (need booth-owner)))
::  booth-owner here is either empty string (not found) or the owner
::    (ship name e.g. ~zod)
...
```

{% endcode %}

## Get a proposal's strategy

Within the `++ action` arm of your custom action handler, obtain booth information using the following hoon. Remember that within the context of the custom-action handler (outer core's `++ on` gate), you have both a booth-key and proposal-key in the context.

Therefore given booth-key and proposal-key (both in custom action context), you can obtain the detail of a proposal as follows:

{% code overflow="wrap" %}

```hoon
::  get a dictionary (map @t json) of proposals for a given booth (by booth-key)
=/  proposals  (~(get by proposals.store) booth-key.context)
=/  proposals  ?~(proposals ~ (need proposals))
=/  proposals  ?:(?=([%o *] proposals) p.proposals ~)
::  get a specific proposal (json) within a booth by querying the proposals
::   return by the calls above
=/  proposal  (~(get by proposals) proposal-key.context)
=/  proposal  ?~(proposal ~ (need proposal))
=/  proposal  ?:(?=([%o *] proposal) p.proposal ~)
::  query the proposal as needed (see proposal detail below)
::  for example, to get the proposal's voting strategy
=/  strategy  (~(get by proposal) 'strategy')
=/  strategy  ?~(strategy 'unknown' (so:dejs:format (need strategy)))
::  strategy will either be 'unknown' (not exists in json)
::    or strategy value (e.g. 'single-choice')
...
```

{% endcode %}

## Get a participant's role

{% code overflow="wrap" %}

```hoon
::  get a dictionary (map @t json) of participants for a given booth (by booth-key)
=/  participants  (~(get by participants.store) booth-key.context)
=/  participants  ?~(participants ~ (need participants))
=/  participants  ?:(?=([%o *] participants) p.participants ~)
::  get a specific participant (json) within a booth by querying the participants
::   return by the calls above
=/  participant  (~(get by participants) participant-key.context)
=/  participant  ?~(participant ~ (need prparticipantoposal))
=/  participant  ?:(?=([%o *] participant) p.participant ~)
::  query the participant as needed (see participant detail below)
::  for example, to get the participant's role
=/  role  (~(get by participant) 'role')
=/  role  ?~(role 'unknown' (so:dejs:format (need role)))
::  role will either be 'unknown' (not exists in json)
::    or role value (e.g. 'member')
...
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.holium.com/ballot/custom-actions/sample-code.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
