Triggering smart action from smart view erroring

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.

  @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

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

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

Many thanks!

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).

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?

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.

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

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

Tell me if it is works.

1 Like

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?

Hey @Talha :wave:

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 :pray: