Apps, pages and deployment

How do I make a button open a URL stored in a form field?

Add a JavaScript action to the button's On click event that reads the field with kf.context.getField and calls kf.client.redirect.

How-to

Short answer: Give the button a JavaScript action that reads the field and redirects to it.

Why it happens

  • The button's Redirection action goes only to your app's pages, the home page, or back to the same page. It can't read a URL held in a field.
  • A JavaScript action can read the field value at run time, and kf.client.redirect opens internal or external URLs.

How to fix it

  1. Select the button and open Event properties.

  2. Add the On click event and choose JavaScript action.

  3. Enter this code, replacing Link with your field ID:

    let link = await kf.context.getField("Link");
    kf.client.redirect(link);
  4. Save and test the button.

To keep the URL out of sight but the redirect working:

  1. Make the field read-only in permissions.
  2. Hide it with a visibility condition.

See button, getField and kf.client.redirect.

Important

If you hide the field through permissions instead of a visibility condition, the script may not be able to read it, and the redirect can fail.

Related answers