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

  • 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? – Ganesh Sanap Jul 16 '19 at 13:33
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".

| improve this answer | |
  • Thanks this worked like charms.. – Pradeep Jul 17 '19 at 7:26
  • Further for learning purpose where can i find more about Regular expressions – Pradeep Jul 17 '19 at 7:27
  • @Pradeep updated my answer – Dylan Cristy Jul 17 '19 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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