# Triggering smart action from smart view erroring

**URL:** <https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626>\
**Category:** Help me!\
**Created:** [May 4, 2022, 11:05am UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626 "2022-05-04T11:05:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Talha](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/talha/32/1062_2.png) [@Talha](https://community.forestadmin.com/u/Talha)\
**Post date:** [May 4, 2022, 11:05am UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/1 "2022-05-04T11:05:19Z")

</div>

## Feature(s) impacted

> Please describe in this **mandatory section** the feature(s) that will be discussed in this topic.

- Smart views triggering a smart action functionality

## Observed behaviour

> Please describe in this **mandatory section** the current behaviour you observe.

- Received an error saying properties of undefined

## Expected behaviour

> Please describe in this **mandatory section** the behaviour you are expecting.

- When the smart view is clicked a smart action will be triggered

## Context

> Please provide in this **mandatory section** , the relevant information about your configuration:

Hi FA community,

I am trying to add some functionality to my smart view, so that when specific text is clicked by the user, a smart action will trigger. However, I am struggling to access the desired smart action. The smart view is located in a collection while the smart action exists in a different collection.

Below is the code used inside the smart views component folder.

```javascript
  @action 
  triggerSmartAction(collection, actionName, records) {
    console.log('line 32')
    return triggerSmartAction(
      this,
      collection, 
      actionName, 
      records, 
    )
  }
  
  @action
  ticket(record){
    console.log(record)
    this.triggerSmartAction("customers", "ticket", record)
  }
}

```

Below is displaying the collection name and smart action declaration inside of my code base

```javascript
collection("customers", {
  actions: [
    {
      name: "ticket",
      type: "single"
    },

```

 ![Screenshot 2022-05-04 at 12.03.47](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8fcf356194985711e93dfe41b24fab4ca19be337.png)

I am unsure why I am receiving the error and was hoping someone could help me identify where I am going wrong.

Many thanks!

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [May 4, 2022, 12:21pm UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/2 "2022-05-04T12:21:20Z")

</div>

Hello,  
I will investigate if it is possible to call a smart action from a smart view of an other collection.

Also, you have this error because FA fails to retrieve your actions.  
In your code example, in the `ticket` action, you should pass at the first argument the context (this).

---

<div class="post-metadata">

**Author:** ![Talha](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/talha/32/1062_2.png) [@Talha](https://community.forestadmin.com/u/Talha)\
**Post date:** [May 4, 2022, 12:47pm UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/3 "2022-05-04T12:47:37Z")

</div>

Thanks for getting back to me Alban!

Oh okay, I thought i could define the context from within the triggerSmartAction action?  
I have added the context to the ticket action and I am still receiving the same result.

Is there any other reasons why it would fail to retrieve the action?

---

<div class="post-metadata">

**Author:** ![Talha](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/talha/32/1062_2.png) [@Talha](https://community.forestadmin.com/u/Talha)\
**Post date:** [May 4, 2022, 2:17pm UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/4 "2022-05-04T14:17:53Z")

</div>

Update:  
It doesn’t seem to like any collection name entered, even if it’s a collection that doesn’t exist. Receiving the same error regardless of name.

I tried moving the action to the collection (smart collection) which contains the smart view and then pointing the triggerSmartAction function towards the same collection. However it is not recognising the smart action?

Is there any special requirements when creating a smart action within a smart collection? I could not find anything on the docs about it.

---

<div class="post-metadata">

**Author:** ![Alban\_Bertolini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alban_bertolini/32/1077_2.png) [@Alban\_Bertolini](https://community.forestadmin.com/u/Alban_Bertolini)\
**Post date:** [May 5, 2022, 8:10am UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/5 "2022-05-05T08:10:44Z")

</div>

I’m back 🙂  
If you want to trigger smart actions to an other collection you can use this code:

```javascript
const myCollection = this.store.peekAll('collection').findBy('name', 'myCollectionName');
this.triggerSmartAction(this, myCollection, "ticket", record);

```

Tell me if it is works.

---

<div class="post-metadata">

**Author:** ![Talha](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/talha/32/1062_2.png) [@Talha](https://community.forestadmin.com/u/Talha)\
**Post date:** [May 5, 2022, 12:17pm UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/6 "2022-05-05T12:17:59Z")

</div>

Thanks for getting back to me,

Yes this works! It allows me to access the smart action in another collection. However, I have an issue with `permissionMiddlewareCreator.smartAction()`, as it’s preventing the logic for the smart action to be accessed?

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [May 6, 2022, 12:43pm UTC](https://community.forestadmin.com/t/triggering-smart-action-from-smart-view-erroring/4626/10 "2022-05-06T12:43:57Z")

</div>

Hey @Talha 👋

Do you have a 403 error when triggering this action?  
Do you have roles configured & is this smart action authorized for your user?

Thanks in advance 🙏
