You are viewing limited content. For full access, please sign in.

Question

Question

Apostrophe in Variable Breaking Hyperlink to WebLink Repository Folder

asked on July 10, 2019 Show version history

I'm creating a hyperlink in a Workflow token that will take an end user to a folder in the WebLink repository.

The folder path contains a "Company Name" variable that may or may not contain an apostrophe.

If the "Company Name" variable does not contain an apostrophe, the hyperlink works without issue.

If there is an apostrophe in the "Company Name", the hyperlink cuts off just before the apostrophe and errors out.

How do I encode an apostrophe in a variable that is used in a WebLink repository hyperlink?

FOLDER PATH

myrepositoryname\Development Services\11 DS Administration\06 Pre-Development Meeting Requests\2019\JOHN DOE'S COMPANY - JOHN DOE - 619

HYPERLINK TOKEN SETUP  my favorite URL Encoder / Decoder website

%3Ca+href%3D%22http%3A%2F%2Fax1dis01%2FWebLink%2FSearch.aspx%3Fdbid%3D0%26searchcommand%3D%7BLF%3ALOOKIN%3D%26quot%3Bmyrepositoryname%5CDevelopment+Services%5C11+DS+Administration%5C06+Pre-Development+Meeting+Requests%5C%(Year)%5C%(EscapedCompany#@EncodeURL@#)%20-%20%(RetrieveBusinessProcessVariablesfromMeetingRequestForm_Applicant_Name#@EncodeURL@#)%20-%20%(BP Instance ID)%26quot%3B%7D%22%3EMEETING%20FILE%3C%2Fa%3E

TRACKED WORKFLOW TOKEN

%3Ca+href%3D%22http%3A%2F%2Fax1dis01%2FWebLink%2FSearch.aspx%3Fdbid%3D0%26searchcommand%3D%7BLF%3ALOOKIN%3D%26quot%3Bmyrepositoryname%5CDevelopment+Services%5C11+DS+Administration%5C06+Pre-Development+Meeting+Requests%5C2019%5CJOHN%2520DOE'S%2520COMPANY%20-%20JOHN%20DOE%20-%20620%26quot%3B%7D%22%3EMEETING%20FILE%3C%2Fa%3E

RENDERED HYPERLINK CUTS OFF AT APOSTROPHE IN "DOE'S"

http://ax1dis01/WebLink/Search.aspx?dbid=0&searchcommand=%7BLF:LOOKIN=%22myrepositoryname%5CDevelopment+Services%5C11+DS+Administration%5C06+Pre-Development+Meeting+Requests%5C2019%5CJOHN%20DOE

ALL THE WAYS I AM CURRENTLY TRYING TO ENCODE THIS APOSTROPHE

  • Custom script activity to force escaping suggested in this fabulous post (working for everything except apostrophes)
  • "EncodeURL" function applied to the "Company Name" variable in the Token Editor (does not encode apostrophes)

 

I appreciate your help!  Thanks so much!

0 0

Answer

SELECTED ANSWER
replied on July 10, 2019 Show version history

I think you have a couple of things going wrong with your encoding.  First is as you point out, the apostraphe is not encoding, but second is that you are encoding too much.  You only want to encode the search command in the URL and not the entire <a> element.

Here is a quick demo workflow with a Script Activity to create the encoded <a> element.  First here is the Script:

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text

Namespace WorkflowActivity.Scripting.Script
    '''<summary>
    '''Provides one or more methods that can be run when the workflow scripting activity is performed.
    '''</summary>
    Public Class Script1
        Inherits ScriptClass90
        '''<summary>
        '''This method is run when the activity is performed.
        '''</summary>
        Protected Overrides Sub Execute()
            'Write your code here.
            Dim sBaseSearchURL As String = "http://ax1dis01/WebLink/Search.aspx?dbid=0&searchcommand="
            Dim sSearchCommand AS String = myURLEncode("{LF:LOOKIN=""" & GetTokenValue("LookinFolder") & """}")
            SetTokenValue("EncodedSearch", sBaseSearchURL & sSearchCommand)
        End Sub

        Function myURLEncode(ByVal strString As String) As String
            strString = strString.Replace("%", "%25")
            strString = strString.Replace("/", "%2F")
            strString = strString.Replace("|", "%7C")
            strString = strString.Replace("?", "%3F")
            strString = strString.Replace("!", "%21")
            strString = strString.Replace("@", "%40")
            strString = strString.Replace("\", "%5C")
            strString = strString.Replace("#", "%23")
            strString = strString.Replace("$", "%24")
            strString = strString.Replace("^", "%5E")
            strString = strString.Replace("&", "%26")
            strString = strString.Replace("*", "%2A")
            strString = strString.Replace("(", "%28")
            strString = strString.Replace(")", "%29")
            strString = strString.Replace("}", "%7D")
            strString = strString.Replace(":", "%3A")
            strString = strString.Replace(",", "%2C")
            strString = strString.Replace("{", "%7B")
            strString = strString.Replace("+", "%2B")
            strString = strString.Replace(".", "%2E")
            strString = strString.Replace("-", "%2D")
            strString = strString.Replace("~", "%7E")
            strString = strString.Replace("-", "%2D")
            strString = strString.Replace("[", "%5B")
            strString = strString.Replace("_", "%5F")
            strString = strString.Replace("]", "%5D")
            strString = strString.Replace("`", "%60")
            strString = strString.Replace("=", "%3D")
            strString = strString.Replace("'", "%27")
            strString = strString.Replace(" ", "%20")
            'strString = strString.Replace(Chr(34), "%22")
            Return strString
        End Function

    End Class
End Namespace

And here is how I created the test Workflow

The HTML_Link value equals

<a href="http://ax1dis01/WebLink/Search.aspx?dbid=0&searchcommand=%7BLF%3ALOOKIN%3D"myrepositoryname%5CDevelopment%20Services%5C11%20DS%20Administration%5C06%20Pre%2DDevelopment%20Meeting%20Requests%5C2019%5CJOHN%20DOE%27S%20COMPANY%20%2D%20JOHN%20DOE%20%2D%20620"%7D">MEETING FILE</a>

 

2 0

Replies

replied on July 10, 2019 Show version history

I think that the reason the URL encoders are not encoding the apostrophe is that it is considered a valid legal html character.

Have you tried to do a simple manual replace to manually encode the apostrophe?  You can try to replace it with:

%27

 

1 0
replied on July 11, 2019

You saved me, Bert!  This worked!

Thank you a million times over! laugh

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.