# Dynamic Buttons, Custom Action & FormAction

**URL:** <https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499>\
**Category:** Rasa Open Source\
**Created:** [July 4, 2019, 2:12pm UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499 "2019-07-04T14:12:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmiiitb](https://avatars.discourse-cdn.com/v4/letter/r/eb9ed0/32.png) [@rmiiitb](https://forum.rasa.com/u/rmiiitb)\
**Post date:** [July 4, 2019, 2:12pm UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/1 "2019-07-04T14:12:01Z")

</div>

Hi,

I need some pointers on calling custom action from formaction. Below is what I’ve done so far -

I have an unfeaturized variable - programGrp that is to be used for populating dynamic buttons. Dynamic, because the button payloads and titles are to be populated from the DB dip. For this I’ve written a custom action - “action\_populate\_prog\_grp”.

Now there are other properties (to be filled) as well, so I’m using FormAction - like name, email etc. The requested\_slots are like this - [“name”, “email”, “phone”, “programGrp”]

I’ve set the slot\_mappings for “programGrp” - “programGrp”: self.from\_entity(entity=“programGrp”),

I’ve created some stories in the interactive mode and have directed to call - “action\_populate\_prog\_grp” before form submit.

Now when I try to run rasa shell, it never predicts “action\_populate\_prog\_grp” and waits for user input after the utterance - “utter\_ask\_programGrp”

So, in a nut-shell how to manage the dynamic buttons in FormAction ?

I’d appreciate if you can give a small example to explain how it’s to be done.

Thanking you in anticipation.

---

<div class="post-metadata">

**Author:** ![rmiiitb](https://avatars.discourse-cdn.com/v4/letter/r/eb9ed0/32.png) [@rmiiitb](https://forum.rasa.com/u/rmiiitb)\
**Post date:** [July 6, 2019, 1:51pm UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/2 "2019-07-06T13:51:15Z")

</div>

Guys, could somebody please help me here.

---

<div class="post-metadata">

**Author:** ![MetcalfeTom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/metcalfetom/32/1422_2.png) [@MetcalfeTom](https://forum.rasa.com/u/MetcalfeTom)\
**Post date:** [July 10, 2019, 11:02am UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/3 "2019-07-10T11:02:19Z")

</div>

Hi @rmiiitb,

I would suggest running a validation within the form to handle this instead of calling a separate action, this way the slot can be filled dynamically within the form code itself. There’s docs on validation actions [here](https://rasa.com/docs/rasa/core/forms/#validating-user-input) and an example of how this works in the [formbot](https://github.com/RasaHQ/rasa/blob/master/examples/formbot/actions.py#L76) too. Try it out and let me know if this doesn’t solve the issue.

---

<div class="post-metadata">

**Author:** ![aniket](https://avatars.discourse-cdn.com/v4/letter/a/c0e974/32.png) [@aniket](https://forum.rasa.com/u/aniket)\
**Post date:** [February 19, 2020, 4:01pm UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/4 "2020-02-19T16:01:42Z")

</div>

Did you got this fixed?i have same issues

---

<div class="post-metadata">

**Author:** ![sachin](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@sachin](https://forum.rasa.com/u/sachin)\
**Post date:** [May 19, 2020, 5:35pm UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/5 "2020-05-19T17:35:52Z")

</div>

Hi @rmiiitb,

I am also having similar problem. Did you find any solution to for it?

---

<div class="post-metadata">

**Author:** ![alkak95](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@alkak95](https://forum.rasa.com/u/alkak95)\
**Post date:** [August 24, 2020, 8:23am UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/6 "2020-08-24T08:23:22Z")

</div>

Hi, What I have understood is you have to add buttons having dynamic title and payload when slot programGrp is asked. Go ahead and overwrite this function “request\_next\_slot”. I have attached code for your reference

def request\_next\_slot(self, dispatcher, tracker, domain):

```
    for slot in self.required_slots(tracker):
        if self._should_request_slot(tracker, slot):
			if slot == 'programGrp':
				//perform your db hit here and append the data in button title and payload
				buttons=[]
				buttons.append({"title": 'dynamic_title', "payload":'dynamic_payload'})
				dispatcher.utter_message(text="Whaterver text or template you have", buttons=buttons)
			
			## For all other slots, continue as usual
            else: 
				dispatcher.utter_message(template=f"utter_ask_{slot}", **tracker.slots)
            return [SlotSet(REQUESTED_SLOT, slot)]
    return None
```

---

<div class="post-metadata">

**Author:** ![adithya12](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/adithya12/32/23036_2.png) [@adithya12](https://forum.rasa.com/u/adithya12)\
**Post date:** [July 27, 2023, 10:35am UTC](https://forum.rasa.com/t/dynamic-buttons-custom-action-formaction/12499/7 "2023-07-27T10:35:32Z")

</div>

hi @alkak95 …need some help please… i was able to create the json for dynamic buttons with for loop from an api response… my problem right now is how can i write an intent to perform an action for a button click which can be anything?

I want to capture the dynamic title clicked by user. I can do it with Tracker data but my problem is how to trigger the action without any intent since I can’t add every possible dynamic title of a button as examples for intent.
