How to script a bolded string in Script Based Default Value?
I am trying to put a bolded string as a Default Value for the Description field, but only for one work item. Therefore, I have to use Script Based Default instead of Multi-Line HTML. How do I need to return the string to get it to show up bolded in the Description field? The Description field is a Large HTML. Cntl+B in the text field manually will work. I have tried: 1) return "<b>Bold this string</b>"; 2) return <b>"Bold this string"</b>; 3) return <b>'Bold this string'</b>; 4) return '<b>Bold this string</b>'; 5) var str = "Bold this string"; var bld = str.bold(); return str;
None of these work. My colleagues have not had luck either. There's got to be a way. Please help. |
One answer
Ralph Schoon (63.5k●3●36●46)
| answered Mar 25 '15, 3:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Mar 25 '15, 3:47 a.m.
As far as I can tell, the syntax is to return a string. Like
return "This is a string"; The Description attribute is of type large HTML. Technically the content syntax is HTML. So the return value would be "<b>bold text</b>". This will be the content of the description if you boldfaced the text. However, this won't work. The description will show "<b>bold text</b>". The reason behind this is that the field is internally managed as XML. To set the XML field from a string, there are two methods. One is to create a valid XML from a plain string. This is the one that apparently has been used. The other one is to expect a valid XML and just put it in. The method that has been chosen changes special characters like < and > into escape sequences. This allows to return something like "1 < 2" without causing an invalid content. Unfortunately the consequence is that you can't really return HTML syntax, because the tags will return with escaped < and > and this results in the result above. The full HTML syntax that I am aware of is return "Plain text<br/><b>bold text</b><br/><i>italic text</i><br/><a href=”https://jazz.net/forum/”>Forum Link</a><br/>User link to <b>@ralph </b><br/>Work Item link to Defect 3 <br/>" However, this does not work with the method chosen for implementation. Instead return "Plain text https://jazz.net/forum/”; User link to @ralph; Work Item link to Defect 3" will result in a valid link, user mentions and work item link being created. This unfortunately does not allow to create breaks or bold face text however. The chosen method allows user with almost no experience return their texts and can't corrupt the attribute value, however, It does not allow to use the full HTML syntax. Comments Please note, I had to escape the special characters in the answer as well, because otherwise the whole syntax would have been messed up. This is a common problem......
Thank you for the response. Just to make sure I understand. Are you saying, it is not possible to create bolded text in a Scripted Default Value? sad face.
Ralph Schoon
commented Mar 26 '15, 3:28 a.m.
| edited Mar 26 '15, 3:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I believe, from my observations and the description above, that it is not possible to create HTML tags in descriptions with JavaScript today. This is due to how a string is converted and stored. This makes it impossible to create bold text using scripts as well.
|
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.