0

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

1
  • How about using ctx.CurrentItem["MultilineJSON"]. Try this and check what are you getting from this? This Multiline text field is Plain or Rich text field? Jul 16, 2019 at 13:33

1 Answer 1

1

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".

3
  • Thanks this worked like charms..
    – Pradeep
    Jul 17, 2019 at 7:26
  • Further for learning purpose where can i find more about Regular expressions
    – Pradeep
    Jul 17, 2019 at 7:27
  • @Pradeep updated my answer Jul 17, 2019 at 13:52

Your Answer

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

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