How to send data to SmartAction (React)

Hello,

I am trying to trigger a SmartAction from a SmartView using React. The SmartAction is created like so:

action "Check Eligibility", type: "single", fields: [
    {
      field: "Facts",
      type: "String",
      is_required: true,
    },
  ]

Basically, I want to take user input from a SmartView and trigger the SmartAction with that user input from within the SmartView when a user clicks a button.

I’ve tried seeing if I could pass in the data to the triggerCustomAction method like so:

this.props.triggerCustomAction(this.props.collection, "Check Eligibility", promotionRecord, data);

Where promotionRecord is one of the records in the collection and data is a string (to be used as the “Facts” field required for the SmartAction).

but this doesn’t seem to work and returns false.

I’m guessing I’m not calling this function correctly or perhaps it’s not supported yet using React? Any help would be appreciated!

Expected behavior

Doing the following will trigger the SmartAction for the current promotionRecord:

this.props.triggerCustomAction(this.props.collection, "Check Eligibility", promotionRecord, data);

Actual behavior

No API call is made and the triggerCustomAction method returns false.

Failure Logs

Please include any relevant log snippets, if necessary.

Context

Please provide any relevant information about your setup.

  • Package Version: forest_liana: 6.3.2
  • Express Version:
  • Sequelize Version:
  • Database Dialect: postgres
  • Database Version: > 9 (I think)
1 Like

Hi @StevenElberger :wave: ,

Thank you for posting this! After discussing this with the team, it’s actually a use case we don’t handle :confused: . We need to improve the way we pass the arguments to allow you to trigger a smart action form from a smart view.

I’ve added this in our roadmap and let you know once we can start working on this!

2 Likes

Hello @StevenElberger

We added a possibility to pass the values from the SmartView in the SmartAction.

Please take into account that the signature of triggerSmartAction is as follows

function triggerSmartAction(
  context, collection, actionName, records, callback = () => {}, values = null,
)

So in order to correctly pass the values, you would need to pass null value for the callback as the 5th argument of the function.

Let me know if you need any help.