Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Formatting script based HTML values

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

0 votes

Comments

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.

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

0 votes


2 other answers

Permanent link
 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>
	

1 vote


Permanent link
 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.

0 votes

Comments

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Jan 07 '14, 7:02 a.m.

Question was seen: 6,617 times

Last updated: Mar 28 '15, 11:54 a.m.

Related questions
Confirmation Cancel Confirm