Skip to main content
swapnar6405
May 30, 2023
Solved

richTextItem, safeLink issue

  • May 30, 2023
  • 10 replies
  • 0 views

Hi,

I have a text field where user is entering website. I am using below line of code to provide a link to the user to navigate to the website.

Issue is when user to try to enter link "www.google.com" or "google.com" and when they came to the link and hit it is throwing an error.

if(
a!isNotNullOrEmpty(ri!site),
a!richTextItem( text: ri!site, link: a!safeLink(uri: ri!site,openLinkIn: "NEW_TAB")
),
""
)

Any suggestions from anyone.

Best answer by mathieud0001

To simplify the data entry of a fully qualified url, I would simply replace any existing occurrences with an empty string and then normalize it at the end. You should also validate it to make sure it is a valid URL, I would suggest using a regular expression for this. https://community.appian.com/b/appmarket/posts/regular-expression-functions.

a!localVariables(
  local!value: "https://google.com",
  concat(
    "https://",
    reduce(
      fn!substitute,
      local!value,
      merge({ "http://", "https://" }, { "", "" })
    )
  )
)

10 replies

mikes0011
Brainy
May 30, 2023
they came to the link and hit it is throwing an error.

I don't have many suggestions without first knowing some detail about the error message the user is getting.  Why not post the error text and/or a screenshot at least?

The two things I can think of in advance:  1) are you doing any sort of verification that the user is typing a valid URL?  2 ) Are you appending "http://" (etc) to the beginning of the URL being supplied, or are you assuming they'll type it?

swapnar6405
May 30, 2023

ERROR Details: 

An Error Has Occurred The record view does not exist or you do not have permission to see it. (APNX-1-4205-015).

Users may enter or may not enter http// or https://, because of free text field.

stewart.burchell
May 30, 2023

I believe you need the full URL e.g. for your example this needs to be: https://www.google.co.uk/.

You'll need to examine the value entered by a user and validate it (which you should be doing anyway) and perhaps add the https:// prefix if they haven't already provided it. Or you could simply insist that a fully qualified url is provided.

swapnar6405
May 30, 2023

How to insist that a fully qualified url entered by the user. Is there a way to use any kind of function to do this in Appian.

stefanhelzle0001
Brainy
May 30, 2023

concat("https://", local!yourUrl)