Question

we need to create a JSLink with multiline text value (Stored as JSON) with values seperated in three different columns

sample schema for MultiLine Column:

[{"email":"John@xyz.com", "skypeid":"testing", "adgroupname":"test1"},{"email":"John1@xyz.com", "skypeid":"testing11", "adgroupname":"test111"}]

if we try to get the value of email using

ctx.ListData.Row[0].MultilineJSON.replace(/"/g,'"')

we get output as below

"[{"email":"<a href="mailto:John@xyz.com">John@xyz.com</a>", "skypeid":"testing", "adgroupname":"test1"},{"email":"<a href="mailto:John1@xyz.com">John1@xyz.com</a>", "skypeid":"testing11", "adgroupname":"test111"}]"

we need to eliminate anchor tag in the output

how can we achieve this?

any help would be appreciated

Was it helpful?

Solution

I do it with two regexes, one for the start of the tag and one for the end of the tag:

var fieldValueString = ctx.ListData.Row[0].MultilineJSON.replace(/"/g,'"');

var regex1 = new RegExp('<a href="mailto.+?">', 'g');
var regex2 = new RegExp('<\/a>', 'g');
fieldValueString = fieldValueString.replace(regex1, '');
fieldValueString = fieldValueString.replace(regex2, '');
var fieldValueJSON = JSON.parse(fieldValueString);

As requested in comments, some further resources for learning about regular expressions:

The Regular Expressions guide on MDN

My preferred online regex tester/playground: regex101.com

And of course, you can find so much more with a simple search for "regex" or "regular expressions".

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top