# Help making action context dependent based upon selected items

**URL:** <https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087>\
**Category:** Developer\
**Created:** [January 27, 2019, 9:30am UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087 "2019-01-27T09:30:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![risto3](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/a87d85/32.png) [@risto3](https://discuss.tryton.org/u/risto3)\
**Post date:** [January 27, 2019, 9:30am UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087/1 "2019-01-27T09:30:49Z")

</div>

I’m looking for a hint on how to make an action context dependent, for example in the invoices tree view to enable the action only when two or more invoices involving the same party are selected.  
(I’d like to add it to the pop-up menu thus as well)  
There doesn’t seem, at first sight, a means to hide the keyword from the action menu via the xml file, how to do so in code then?  
Pointer to existing example is welcome!  
BTW, disabling is needed in the form view as well.

---

<div class="post-metadata">

**Author:** ![JCavallo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@JCavallo](https://discuss.tryton.org/u/JCavallo)\
**Post date:** [January 28, 2019, 8:30am UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087/2 "2019-01-28T08:30:01Z")

</div>

Hi,

You can do part of that by using a button with the “keyword” attribute set : [Button location in the toolbar is hardcoded to be on the Action button (#7067) · Issues · Tryton / Tryton · GitLab](https://bugs.tryton.org/issue7067)

Basically, declare a button with the appropriate states, then use the keyword attribute when adding the button to your view to say in which menu it should appear.

However, your particular use case will probably not be possible, since it depends on multiple selected lines, and there is no way as far as I know to access those multiple lines in an Eval statement.

---

<div class="post-metadata">

**Author:** ![risto3](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/r/a87d85/32.png) [@risto3](https://discuss.tryton.org/u/risto3)\
**Post date:** [January 28, 2019, 3:42pm UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087/3 "2019-01-28T15:42:29Z")

</div>

is it possible to check len(Transaction().Context[‘active\_ids’]) \>2?

---

<div class="post-metadata">

**Author:** ![JCavallo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/j/48db29/32.png) [@JCavallo](https://discuss.tryton.org/u/JCavallo)\
**Post date:** [January 28, 2019, 3:58pm UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087/4 "2019-01-28T15:58:35Z")

</div>

I am almost sure that states on buttons are only evaluated if only one line is selected @ced ?

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [January 28, 2019, 4:42pm UTC](https://discuss.tryton.org/t/help-making-action-context-dependent-based-upon-selected-items/1087/5 "2019-01-28T16:42:42Z")

</div>

> [@risto3](#):
>
> is it possible to check len(Transaction().Context[‘active\_ids’]) \>2?

You can with the [len operator of pyson](http://docs.tryton.org/projects/server/en/latest/ref/pyson.html?highlight=Len#trytond.pyson.Len):

```
Len(Eval('active_ids', [])) > 2

```
