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
Ralph Schoon (63.5k●3●36●46)
| 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
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");
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> |
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
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.
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.
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'.