It's all about the answers!

Ask a question

Formatting script based HTML values

James Hewitt (4258) | asked Jan 07 '14, 7:02 a.m.
edited Jan 07 '14, 10:10 a.m.
Using the Default Value based attributes customization (Script based) I can add a default text in the  description based on the work item type. 

This is working fine, however to make it nicer (as possible with the Multiline text) I would like to add some basic formatting. I've noticed that using <br/> in the returned script adds a new line, but using <b> results in having <b> in the description.

A quick addition here: Adding <br/> in the text adds a newline in the web client, but not in the eclipse client. Adding \n doesn't work at all.

This is RTC
Also tested on RTC 4.0.5

James Hewitt commented Jan 13 '14, 6:29 a.m.

I managed to get newlines to work across both clients by using 
 in the string instead of \n, so they pass through the javascript properly.

Would still like to know how to use HTML.

Matt Hillary commented Mar 27 '15, 6:20 p.m. | edited Mar 28 '15, 5:05 a.m.

Hi James,

I'm having the same problem with RTC version 4.0.6.  I'm trying to put an HTML link (a href=...) inside a calculated field, then display that HTML (link) in the editor presentation.  However, even if I use < or < for the 'less than' signs, and > or > for the 'greater than' signs, it still shows up in the UI exactly as the calculated value.

Any idea if I'm doing something wrong?  Or if there's something else I can try? If it helps, I have my attribute type as 'Medium HTML'.

Accepted answer

permanent link
Ralph Schoon (63.2k33646) | answered Mar 28 '15, 5:08 a.m.
 You can't. There was a similar question recently and I had a look. The string gets returned and then in the API it is converted into an XML string using a method that escapes special characters like > etc. since you are not in control of that conversion, I dont see a way to circumvent that.
Ralph Schoon selected this answer as the correct answer

2 other answers

permanent link
James Hewitt (4258) | answered Jan 07 '14, 10:08 a.m.
 Just to share the code I'm using to set the default value for a field based on the type of the work item, here is the custom script:

(Code based on examples from jazz articles)
(function() {
    dojo.declare("", null, {
        getDefaultValue: function(attribute, workItem, configuration) {
            var type = workItem.getValue(WorkItemAttributes.TYPE);
            var values = configuration.getChildren("default");
            var result = "";
            for (var i = 0; i < values.length; i++) {
                if (type == values[i].getString("type")) result = values[i].getString("value"); 
            return result;
And to use it, you need to add it as a default value provider:
<configuration-data final="false" id="" xmlns="">
  <defaultValueProvider id="" name="Default String by Type" providerId="">    
    <script class="" path="/workitem/scripts/common/defaultStringByType.js"/>
And then assign it to the description with some values:
<attributeDefinition id="" name="Description" type="html">
  <defaultValueProvider providerId="">
    <default type="defect" value="Default description for a defect"/>

permanent link
Matt Hillary (11) | answered Mar 28 '15, 11:39 a.m.
 Thanks for the reply Ralph.  We found something that worked for us.  Since we're creating all these work items via the plain Java API initially, if we set the HTML field at that time and not rely on a calculated field, the HTML field displays the HTML that we set via the Java API.

Ralph Schoon commented Mar 28 '15, 11:54 a.m.

Hi Matt, yes with the Java API you can use a method to create the XML that does not convert the tags. 

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.