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.

Edit:
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 4.0.0.1
Also tested on RTC 4.0.5

Comments
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.1k33646) | answered Mar 28 '15, 5:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 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)
dojo.provide("com.ibm.team.workitem.DefaultStringByType");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
    var WorkItemAttributes=com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.ibm.team.workitem.DefaultStringByType", 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="com.ibm.team.workitem.configuration.providers" xmlns="http://com.ibm.team.workitem/providers">
<defaultValueProviders>
  <defaultValueProvider id="com.ibm.team.workitem.DefaultStringByType" name="Default String by Type" providerId="com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider">    
    <script class="com.ibm.team.workitem.DefaultStringByType" path="/workitem/scripts/common/defaultStringByType.js"/>
  </defaultValueProvider>
</defaultValueProviders>
</configuration-data>
	
	
And then assign it to the description with some values:
<attributeDefinition id="com.ibm.team.workitem.attribute.description" name="Description" type="html">
  <defaultValueProvider providerId="com.ibm.butterfly.rtc.DefaultStringByType">
    <default type="defect" value="Default description for a defect"/>
  </defaultValueProvider>
</attributeDefinition>
	

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.

Comments
Ralph Schoon commented Mar 28 '15, 11:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.