# Dashboard fails to trigger smart action

**URL:** <https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886>\
**Category:** Feature suggestions\
**Tags:** howtos\
**Created:** [December 10, 2021, 3:15pm UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886 "2021-12-10T15:15:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![arms](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arms/32/3305_2.png) [@arms](https://community.forestadmin.com/u/arms)\
**Post date:** [December 10, 2021, 3:15pm UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/1 "2021-12-10T15:15:35Z")

</div>

Hello Forest Admin team 👋

## Feature(s) impacted

I want to trigger a smart action from a dashboard, it works perfectly from a smart view that is attached to a collection.

## Observed behavior

I have the following code for my smart action, it get triggered correctly

```javascript
  @action
  deleteShift(records, values) {
 return triggerSmartAction(
      this,
      this.args.collection, // <--- This seems to be the problem.
      "Delete",
      records,
      () => {},
      values
    );
  }

```

this.args does not have collection.

## Expected behavior

The exact same code works when the smart chart is attached to a collection.

## Failure Logs

I have the following error log in the browser console:

```javascript
TypeError: Cannot read properties of undefined (reading 'customActions')

```

## Context

- Project name: \*\*\*\*\*\*\*-trial
- Team name: Operations
- Environment name: Development

---

<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:** [December 13, 2021, 9:08am UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/2 "2021-12-13T09:08:09Z")

</div>

Hey @arms 👋

Indeed, `this.args.collection` will definitely cause issue in a Dashboard/smart chart context, since Dashboard are not directly attached to a collection.

Could you eventually try `this.args.chart.sourceCollection` instead of `this.args.collection`?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![arms](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arms/32/3305_2.png) [@arms](https://community.forestadmin.com/u/arms)\
**Post date:** [December 13, 2021, 10:08am UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/3 "2021-12-13T10:08:01Z")

</div>

@anon39848301 👋 !

Thank you for the suggestion, I tried the following thing:

```javascript
     return triggerSmartAction(
          this,
          this.args.chart.sourceCollection,
          "Delete",
          records,
          () => {},
          values
        );

```

But it still fails, maybe I got you wrong.  
I have the following error:

```javascript
Uncaught TypeError: Cannot read properties of undefined (reading 'sourceCollection')

```

It seems that this.args does not have chart property.

---

<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:** [December 13, 2021, 10:22am UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/4 "2021-12-13T10:22:54Z")

</div>

No, that’s my fault, I was thinking the chart may carry this info, but I mis-read the code 😅  
Could you eventually share here or privately the complete code of your smart chart so I can check if I can find a way to access a collection from there? Thanks 🙏

---

<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:** [December 13, 2021, 10:44am UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/5 "2021-12-13T10:44:51Z")

</div>

Otherwise, you could also just use the `store` service to retrieve the collection from there.

```javascript
import Component from '@glimmer/component';
import { loadExternalStyle, loadExternalJavascript } from 'client/utils/smart-view-utils';
import { inject as service } from '@ember/service';

export default class extends Component {
  @service store;
  
  
  constructor(...args) {
    super(...args);
    console.log(this.store.peekRecord('collection', 'yourCollectionName'));
  }
}

```

---

<div class="post-metadata">

**Author:** ![arms](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arms/32/3305_2.png) [@arms](https://community.forestadmin.com/u/arms)\
**Post date:** [December 13, 2021, 12:48pm UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/6 "2021-12-13T12:48:30Z")

</div>

Nice ! I tried with the retrieved collection from the _store_ service as follow:

```javascript
     return triggerSmartAction(
          this,
          this.store.peekRecord('collection', 'shift'),
          "Cancel",
          records,
          () => {},
          values
        );

```

But I run into this error:

```javascript
Uncaught (in promise) TypeError: r(...).triggerCustomAction is not a function

```

This is the import line:

```javascript
import { triggerSmartAction } from 'client/utils/smart-view-utils';

```

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [December 13, 2021, 2:07pm UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/7 "2021-12-13T14:07:47Z")

</div>

Hi @arms 👋, i’m afraid it is not possible yet 😕.  
I push your request to our product board. Thanks a lot for your feedback 🙏

---

<div class="post-metadata">

**Author:** ![arms](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arms/32/3305_2.png) [@arms](https://community.forestadmin.com/u/arms)\
**Post date:** [December 13, 2021, 5:55pm UTC](https://community.forestadmin.com/t/dashboard-fails-to-trigger-smart-action/3886/8 "2021-12-13T17:55:51Z")

</div>

Hey !

Thank you @anon39848301 and @Arnaud_Moncel ! Cannot wait to see this feature available 😃 !

Keep it up guys !  
Cheers
