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
Accepted answer
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.
2 other answers
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>
Comments
James Hewitt
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.
Matt Hillary
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'.