Open oshihirii opened 2 years ago
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"
}
}
]
}
The method without replaceAll did not filter properly for me as well.
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
Sample
https://github.com/pnp/List-Formatting/tree/master/column-samples/generic-hyperlink-values
Question
The code shown in the example above:
works well as long as the dynamic URL:
&
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:
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?