Question

Seems like it would be a simple thing really (and it may be), but I'm trying to take the string data of a column and then through a calculated column, replace all the spaces with %20's so that the HTML link in the workflow produced email will actually not break off at the first space.

For example, we have this in our source column:

file:///Z:/data/This is our report.rpt

And would like to end up with this in the calculated column:

file:///Z:/data/This%20is%20our%20report.rpt

Already used the REPLACE, and made up a ghastly super nested REPLACE/SEARCH version, but the problem there is that you have to nest for EACH potential space, and if you don't know how many up front, it doesn't work, or will miss some.

Have any of you come across this scenario and how did you handle it?

Thanks in advance!

Was it helpful?

Solution

As far as I know there is no generic solution using the calculated-column syntax. The standard solution for this situation is using an ItemAdded (/ItemUpdated) event and initializing the field value from code.

OTHER TIPS

so that the HTML link in the workflow produced email will actually not break off at the first space.

The browser only does this if you have not enclosed your link in quotes

If you wrap the link in quotes, it does not cut off at the first space

In a SharePoint Formula it would be:

="""file:///Z:/data/This is our report.rpt"""

becuase two quotes are the SP escape notation to output a quote

You can use this formula (Start trim for 1, in my case was 4):

=IF(ISBLANK([EUR Amount]),"",(TRIM(MID([EUR Amount],4,2))&TRIM(MID([EUR Amount],6,2))&TRIM(MID([EUR Amount],8,2))&TRIM(MID([EUR Amount],10,2))&TRIM(MID([EUR Amount],12,2))&TRIM(MID([EUR Amount],14,2)))*1)

I was able to solve this issue for my circumstances by using a series of calculated columns.

In the first calculated column (C1) I entered a formula to remove the first space, something like this:

=IF(ISNUMBER(FIND(" ",[Title])),REPLACE([Title],FIND(" ",[Title]),1,"%20"),[Title])

In the second Calculated column (C2) I used:

=IF(ISNUMBER(FIND(" ",[C1])),REPLACE([C1],FIND(" ",[C1]),1,"%20"),[C1]).

In my case, I wanted to encode upto four spaces, so I used 3 calculated columns (C1, C2, C3) in the same fashion and got the desired result.

This is not as efficient as using a single calculated column, but if SUBSTITUTE will not work in your SharePoint environment, and you cannot use an event handler or workflow, it may offer a workable alternative.

I actually used a slightly different formula, but it was on a work machine to which I don't have access at the moment, so I just grabbed this formula from a similar S.O. question. Any formula that will replace the first occurrence of a space with "%20" will work, the trick is to a) make sure the formula returns the original string unchanged if it does not have more spaces in it, and b) test, test, test. Create a view of your list that has the field you are trying to encode, plus the calculated fields, and see if you are getting the results you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top