How Can I Replace Text Characters in RTC via Attribute Customization Javascript?
I am writing an attribute customization script in RTC to evaluate the contents of a Work Item's description field. I want to be able to do a compare on the text and disregard any HTML formatting that may be present. To do this, I am trying to perform a javascript replace function on the text string that I am evaluating. However, the replace function isn't working. It isn't causing an error, but it's not having any effect either.
Example:
Input:text = "<b>Solutions Considered:</b><br/>";
Replace command:
text = text.replace(/<b>|<\/b>|<i>|<\/i>|<br\/>/, "");
Expected result:
text = "Solutions Considered:"
Actual result:
text = "<b>Solutions Considered:</b><br/>";
I've tested this in a JavaScript editor and it produces the expected results there. Does RTC not support the JavaScript replace function? Do I need to specify a dojo.require command in order to have the replace work as expected?
P.S. Jazz.net, you guys really need to figure out how to allow me to display HTML tags without interpreting them as HTML.3 answers
Comments
Do you mean the replace command? The first string in my post already is wrapped in quotes. Although technically, I'm not defining that string in my actual code. It's just what I'm getting from the description attribute of the work item. I could use quotes on the replace command, but then it wouldn't be a regex literal. I may have tried that previously, but I could look at it again.
I have a console.log statement which shows the content to have HTML tags in it. Although another answer below suggests that maybe the HTML tags are being displayed as HTML but are really represented as encoded HTML (e.g., < ; b & gt;). I am dubious that the console.log command would render that kind of text as brackets though. I would think console.log would just handle stuff as strings.
The console log dumps strings. I referred to the Java API (and the JavaScript API).
If you use the editor actions to create links or the automation it will be HTML tags. If you try to set HTML e.g. from JavaScript, you end up with escaped tags. We had that discussion recently in this forum for JavaScript.
Ralph, I found this old post I had submitted while searching for a new (but related) question. The new question is actually relevant to what you seem to be referencing in this comment above. I want to manipulate an HTML attribute and preserve existing HTML tags. Can you point me to the other thread in this forum where that discussion was had?
Nate, I don't know where that was, however I know how the Java API does it and it uses a special method to set an XML string which keeps the content as it is and another to set it from plain text in which case the string content is escaped. So the HTML show up as text and don't work. that seems to be the only method I am aware of that the attribute customization API supports.
There should be internal stuff in the web UI that allows more. But I have never been able to set real HTML content with JavaScript for attribute customization.
Comments
I did indeed have a console.log statement in there and the text had several <br/> instances in it. There was also at least one instance of <b>. I did a console.log output of the string before and after and there was no change. In my JavaScript test environment though, the replace command worked as expected.
I suppose I could try doing a replace on & l t ; I hadn't tried that yet. I'm not terribly optimistic at this point though.
If the data in the text shows up as html tag, then it is escaped. If it is a real link, or the tags show e.g. a newline, the text is not escaped.
Fundamentally there are two methods to put content into those attributes. One creates the XML content from a plain text and escapes tags and one that assumes a valid XML/HTML and does not escape. JavaScript uses the first one, the UI the latter.
Also, I would try some plain text replaces to verify that the javascript function works correctly in the extension
I also encountered the same issue. I was auto-populating Description field based on value of an enumeration and was getting HTML value instead of text in Description field.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER Apr 08 '15, 3:01 a.m.Please file an enhancement request, if you want this to happen.