Unable to pass hidden field from Action to Form

I’m trying to pass a hidden field from an Action to a new Form I’m building via this code:

exports.onExecutePostLogin = async (event, api) => {
  api.prompt.render('ap_1REWW3UztkwjxdGPbqsCya', {
    fields: {
      update_profile: "true",
    }
  });
}

However, when I reference the hidden field named update_profile, the form seems to break. Am I doing this incorrectly? Any additional information on how to pass variables from an Action to a Form would be greatly appreciated.

Router setting I’m trying to use (which always just gets the default):

Hi @devans,

I have tested this on my end and was able to get it to work successfully without issues.

The first thing you might want to include in your Post Login action script is the onContinuePostLogin function, which allows the form to resume the authentication flow.

exports.onExecutePostLogin = async (event, api) => {
  api.prompt.render('ap_1REWW3UztkwjxdGPbqsCya', {
    fields: {
      update_profile: "true",
    }
  });
}

exports.onContinuePostLogin = async (event, api) => {
  // (Optional) Add your logic after completing the form
}

Next, if your form seems to break, please ensure that your router connects a path for all conditions, including the default case. See the example below:

Once that’s complete, the forms will render correctly.

Let me know how this goes for you.

Thanks,
Rueben

Hi @rueben.tiow !

Thank you for taking the time to replicate this flow on your end. I still seem to be having the same issue where the value doesn’t change the flow when the router is defined?

Here are some more screenshots which should outline everything I’m doing. Basically I just want to have the variable update_profile be passed from the Action to the form flow:

Do I need to add anything else for this logic to work? The code as is always goes into the default case when I want to determine the flow within the Action via the update_profile.

Hi @devans,

Can you share a screenshot of the configuration for your Step as well?

Thanks,
Rueben

Hey @rueben.tiow,

Here’s a screenshot of the Step which is basically just a test that doesn’t do anything:

I was just using that to test the variable being used that I’m trying to pass from the Action itself.

1 Like

Hi @devans,

Thanks for sharing the screenshot.

I have identified the issue. Essentially, your Post Login action script does not reference the correct ID. It should reference the ID you defined in your Step settings, ’ test_input_id`.

So, in your Post-Login action script, it should be:

exports.onExecutePostLogin = async (event, api) => {
  var app_id = "YOUR_APP_ID"
  api.prompt.render(app_id, {
    fields: {
      update_profile: "true"
      test_input_id: "Any text you want here"
    }
  });
};

When done this way, it will populate the fields correctly.

Could you try this and let me know how it goes?

Thanks,
Rueben

Hi @rueben.tiow,

The step I included was just to test the flow of the form itself. What I was trying to accomplish was to route the user using the Router based on a value (update_profile) which should be set in the action itself. I.e. if the value of update_profile is true (passed from the Action), I want the user to update their profile. If it’s false (default case) I want to just sign them in. Is that possible?

Hopefully that makes sense. I’m trying to use the value passed from the Action to do the initial Router logic before the user is taken to any form.

Thanks for your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.