SOLVED

SharePoint JSON Formatting using split and the resulting array

Copper Contributor

Hello,

at https://learn.microsoft.com/de-de/sharepoint/dev/declarative-customization/formatting-syntax-referen... I did find this for the split operator:

 

  • split: divides the given string into an ordered list of substrings by searching for the given pattern, and returns an array of these substrings
    • "txtContent": "=split('Hello World', ' ')" returns an array with 2 strings - 'Hello' and 'World'

      This returns: Hello, World

Now with that given - I use this:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=split([$Supervisor.email], '@')"
}

 

This returns: first.name,domain.com

It does what it should. However my question is how can I address the array? So for example that only the index 0 of the array will be returned? Means only: first.name 
Or index 1 of the array, which would return only: domain.com

At the end I need all elements of the array to build a new string I need. I want to create a delve link of the user profile to be opened at a new browser tab. I have all working except the string rebuild of the email.

Side note: I have used the replace operator to solve my problem (not mentioned and shown here!)

But, I want to learn more and like to know, how to use the split operator and access each operand of the array individually.

Somebody knowing it and can explain?
Many thanks for teaching me in advance.
Cheers
JK

2 Replies

@_J-K_  try to use 

"=substring(@currentField.email, 0, indexOf(@currentField.email,'@'))" and subsequently for other part and instead of putting textContent you can add as much as elemType in children attribute something like this :

"children": [
{
"elmType": "span",
"txtContent": "=substring(@currentField.email, 0, indexOf(@currentField.email,'@'))"
},
{
"elmType": "span",
"txtContent": "=substring(@currentField.email, indexOf(@currentField.email,'@'), length(@currentField.email))"

}
]

 

I haven't tested but you get more info from this link https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/formatting-syntax-referen...

 

 

Br,

Suvi

 

Please free to ask question, if this solves your purpose mark this as answered. 

 
best response confirmed by _J-K_ (Copper Contributor)
Solution

@_J-K_ 

 

I couldn't find a way to access the resulting array either.

 

Like @suvi-15 pointed you can use the substring instead. But in this case, accessing another field requires this markup [$ColumnName] and not the @ColumnName

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "=substring([$Supervisor.email], 0, indexOf([$Supervisor.email],'@'))"
}

 

Additional note: I couldn't access a field that has a space in it.
ex.:
[$Supervisor Info.email] doesn't work.
[$SupervisorInfo.email] works.

1 best response

Accepted Solutions
best response confirmed by _J-K_ (Copper Contributor)
Solution

@_J-K_ 

 

I couldn't find a way to access the resulting array either.

 

Like @suvi-15 pointed you can use the substring instead. But in this case, accessing another field requires this markup [$ColumnName] and not the @ColumnName

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "=substring([$Supervisor.email], 0, indexOf([$Supervisor.email],'@'))"
}

 

Additional note: I couldn't access a field that has a space in it.
ex.:
[$Supervisor Info.email] doesn't work.
[$SupervisorInfo.email] works.

View solution in original post