2

OK, I have a customer name and address and simply want to display this in one computed field instead of separate lines in a table to save real estate. I've tried several iterations of @newline but to no avail. Can someone give me some guidance?

I would also like to NOT include Address2 if it's blank. I'm new to javascript. Thanks for your help.

var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
var d = @Char(13);
a + @NewLine() + b + "<br>" + c;

2 Answers2

5

Set property escape="false" in computed field and add <br /> whenever you want a newline.

You can set this property in properties tab selecting content type "HTML" too:

enter image description here

Your code would be

var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
a + "<br />" + b + (c ? "<br />" + c : "");
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • Could do the same without HTML and add in newline characters `\n` instead of HTML break tags. – Eric McCormick Oct 15 '15 at 16:34
  • @Eric: unfortunately, `\n` doesn't work. Text rows are divided by newline inside a span when sent to browser but browser changes newlines to spaces. – Knut Herrmann Oct 15 '15 at 17:24
  • Completely right re: the `span` tag. I know I've done this before, but whatever I must have done at the time would probably be more intensive that switching to HTML content. – Eric McCormick Oct 15 '15 at 18:49
  • Be aware that using escape=false with user-submitted data can give Cross Site Scripting (XSS) security vulnerabilities. e.g malicious user A sets their address to: `` And then innocent user B looks at user A's address, user B's info is sent to user A's server, and user A can pretend to be user B. Using escape=true ensures that ` – Maire Kehoe - IBM Oct 27 '15 at 15:42
4

Mike,

I had to do nearly the same thing recently and used a Multiline Edit Box. Place your same code in data section of an <xp:inputTextArea> (Multiline Edit Box in palette) and then make it read-only.

enter image description here

Steve Zavocki
  • 1,840
  • 4
  • 21
  • 35