0

I'm trying to extract the account part of email in a person column ("created by" or Author). I want to the account part so I can concatenate a text for form an URL, such as http://somesite.com/jdoe.jpg if, for instance, the author's email is [email protected].

Following the Microsoft documentation, I tested this:

"txtContent":"=replace([$Author.email], '@email.com', '.jpg')"

The result just displayed the full email ('[email protected]'). Any reason why this doesn't work?

Incidentally, I tried an alternative with the split operator, as in:

"txtContent":"=split([$Author.email], '@')"

This return the following:

jdoe,

But I couldn't replace the separating comma either. I would appreciate any ideas on how I can get what I'm looking for.

1 Answer 1

0

Maybe there is some issue with replace operator in SharePoint JSON formatting at Microsoft end.

Instead of replace operator, try using replaceAll operator.

Example:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "='http://somesite.com/' + replaceAll([$Author.email], '@contoso.com', '.jpg')"
}

Reference: SharePoint: Replace All Occurrences of Substring in a String using JSON Formatting

Output:

enter image description here

Also, make sure you have included/shown Created By column in list view.


Update:

replace operator in JSON formatting also works, but you have to convert Author email to string explicitly like:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "='http://somesite.com/' + replace('' + [$Author.email] + '', '@contoso.com', '.jpg')"
}

Where Author is internal name of SharePoint default Created By column. You can get internal name of any SharePoint list column by following this article: How to find the Internal name of columns in SharePoint Online?

1
  • 1
    ah, gotcha. This worked. Thanks a lot
    – Wal
    Jun 3, 2023 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.