Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have a question about SAMPLE generic-hyperlink-values #584

Open
oshihirii opened this issue Sep 3, 2022 · 3 comments
Open

I have a question about SAMPLE generic-hyperlink-values #584

oshihirii opened this issue Sep 3, 2022 · 3 comments
Assignees
Labels
❓ Question Question about one of the samples

Comments

@oshihirii
Copy link

Sample

https://github.com/pnp/List-Formatting/tree/master/column-samples/generic-hyperlink-values

Question

The code shown in the example above:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "attributes": {
    "target": "_blank",
    "href": "='http://finance.yahoo.com/quote/' + @currentField"
  }
}

works well as long as the dynamic URL:

  • isn't a link to a SharePoint resource
  • which includes characters such as an ampersand &

For example, I am trying to generate a dynamic URL based on the value in another column.

The dynamic URL is a link to a filtered view of a document library, eg:

"attributes": {
  "target": "_blank",
  "href": "='https://tenant-name.sharepoint.com/sites/site-name/cd/Forms/My%20View%20Name.aspx?env=WebViewList&FilterField1=My_x0020_Reference&FilterValue1=' + [$Title]"
}

If the value in the other column includes an ampersand &, the URL breaks when clicking on the dynamic URL.

Is there anyway to URL encode the column value when adding it to the dynamic URL?

@oshihirii oshihirii added the ❓ Question Question about one of the samples label Sep 3, 2022
@tecchan1107 tecchan1107 self-assigned this Sep 6, 2022
@tecchan1107
Copy link
Collaborator

Hi @oshihirii !
How about replacing & with %26 using the replaceAll operator?
I tried the following method of using the replaceAll operator and was able to filter successfully even if the value contained &.

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "children": [
    {
      "elmType": "a",
      "txtContent": "@currentField",
      "attributes": {
        "href": "= 'https://<<tenantName>>.sharepoint.com/sites/<<siteName>>/<<documentLibraryName>>/Forms/<<View>>.aspx?FilterField1=Choice&FilterType1=Choice&FilterValue1=' + replaceAll(@currentField,'&','%26')",
        "target": "_blank"
      }
    }
  ]
}

image

@tecchan1107
Copy link
Collaborator

The method without replaceAll did not filter properly for me as well.

@oshihirii
Copy link
Author

Hi @tecchan1107 ,

Thankyou, it is a good idea and your approach is what I am implementing now.

For it to be a truly thorough solution, I am wondering if somebody smarter than me could figure out a replaceAll() that replaces all characters that SharePoint requires to be replaced in the URL.

That way we could be confident that any value we are grabbing from another column to create a filtered list URL (using JSON formatting) will be encoded as required.

I guess it would basically imitate an encodeURI() function.

The first step would be defining all the illegal characters in a SharePoint list URL.

I have searched and the only illegal characters I come across are those relating to file names, eg:

" * : < > ? / \ |

But I am not sure if they are the same characters that are not allowed in a SharePoint list URL.

Related Reading:

Restrictions and limitations in OneDrive and SharePoint > Invalid characters

Query String URL Tricks for SharePoint and Microsoft 365

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ Question Question about one of the samples
Projects
None yet
Development

No branches or pull requests

2 participants