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

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.

0 votes

Comments

Please file an enhancement request, if you want this to happen.



3 answers

Permanent link
 did you try wrapping the 1st string in quotes? 

also, do you know that the string has the html in it at the time you are doing the replace? 

0 votes

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., &lt ; 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.


Permanent link
 Like Sam said,  you'd better do some debugging to make sure the string being processed is what you believe to be. For example, the " < b > " may already be "escaped" to " & l t ; b & g t ; " when your script "sees" the string. Note the script may be evaluated on both the client and server side, and you have to debug it in both cases. Function console.log() should be a good starting point.

0 votes

Comments

I did indeed have a console.log statement in there and the text had several &lt;br/&gt; instances in it. There was also at least one instance of &lt;b&gt;. 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


replace 'aa' with 'bb' in some text fields. 


Permanent link
RTC v 6.0.2

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.

I made some modifications in the script which resolved it.
This answer is in continuation of my previous question.
Pasting the working script below.

dojo.provide("com.example.DescriptionValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojox.html.entities");

(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.example.DescriptionValue", null, {

        getValue: function(attributeId, workItem, configuration) {
                   
var attr = "com.ibm.team.workitem.attribute.business"; // ID of attribute Business. (Business is an enumeration)
var val_bus = workItem.getValue(attr);
var descrip = workItem.getValue(WorkItemAttributes.DESCRIPTION);
if(descrip === ""){
if (val_bus === "com.ibm.team.workitem.enumeration.business.literal.l4"){
descrip = "Description: \nWhere and when found: \nHow found: ";
return descrip;
}
else if (val_bus === "com.ibm.team.workitem.enumeration.business.literal.l6"){
descrip = "Description:\nObservation:\nSafety Impact:";
return descrip;
}
}
descrip = dojox.html.entities.decode(descrip); // This is removing all characters except <br/>
var br_def = "<br/>";               // Below lines are to check if multiple <br/> are present and remove all.
while(descrip.includes(br_def)){
var i = 0;
descrip = descrip.replace('<br/>','\n');
}
return descrip;
        }
   });
})();

0 votes

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

Question asked: Apr 07 '15, 4:20 p.m.

Question was seen: 6,293 times

Last updated: Feb 07 '17, 8:29 a.m.

Confirmation Cancel Confirm