Data Management Capabilities > Managing Change > Change Management Administration > Converting a Rich Text Attribute to a Simple Text Attribute
Converting a Rich Text Attribute to a Simple Text Attribute
Use APIs such as getLongDescription, getLongProposedSolution, and getLongReason to fetch rich content like longDescription, longProposedSolution, longReason, respectively, with markup tags.
Use APIs such as getDescription, getProposedSolution, and getReason to fetch plain text values of a description, proposed solution, and reason.
To convert rich content (with markup tags) into simple plain text, use the following code:
String richText = ChangeOrder2(Instance).getLongDescription()
HTMLText htmlAttr = HTMLText.newHTMLText(richText);
plainText = htmlAttr.getPlainText();
Converting Rich Text Attribute to Simple Text Attribute for Replication Packages
While exporting any change object package to Windchill, if the rich text attributes such as longDescription, longProposedSolution, and longReason are excluded, you can customize the source system to convert the rich text attributes exported from the source to simple text attributes. The customization removes the existing attributes: description, proposedSolution, and reason and converts the attributes: longDescription to description, longReason to reason, and longProposedSolution to proposedSolution. As a result, the rich text values get converted to simple text values.
Perform the following steps for customization:
1. As per the type of change object, access the respective file from this path: <WT_HOME>\codebase\registry\XSLRepo\11.0.M030:
WTChangeActivity2.xsl
WTChangeIssue.xsl
WTChangeOrder2.xsl
WTChangeRequest2.xsl
WTVariance.xsl
* 
In this example, we are using the WTChangeIssue.xsl file.
2. Add the following lines of code in the file:
a. To remove the existing description attribute:
<xsl:template match="WTChangeIssue/description"></xsl:template>
b. To replace the longDescription attribute with description:
<xsl:template match="WTChangeIssue/longDescription">
<description>
<xsl:call-template name="plainTextFilter" />
</description>
</xsl:template>
* 
The code also calls an XSL template named plainTextFilter, which will be defined subsequently.
c. To import the plainTextFilter template:
<xsl:import href="plainTextFilter.xsl" />
3. Create a file named plainTextFilter.xsl at the location: <WT_HOME>\codebase\registry\XSLRepo\11.0.M030 and add the following lines of code in the file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:filter="java:com.custom.text.conversion.PlainTextConverter" >
<xsl:template name="plainTextFilter">
<xsl:value-of select="filter:convertToPlainText(.)" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
This calls the convertToPlainText method of a custom class com.custom.text.conversion.PlainTextConverter. This method will contain rich text string value as the input parameter and return simple text string value.
4. Create a class named PlainTextConverter to define the custom class given above:
package com.custom.text.conversion;
import com.ptc.commons.lang.util.StringEscapeUtils;
import com.ptc.core.richtext.HTMLText;

public class PlainTextConverter {
public static String convertToPlainText(String rawText) {
HTMLText htmlAttr;
String plainText = " ((null))";
try {
if (null != rawText && !rawText.isEmpty()) {
htmlAttr = HTMLText.newHTMLText(rawText);
plainText = htmlAttr.getPlainText();
plainText = StringEscapeUtils.escapeXml(plainText);
}
} catch (Exception exp) {
exp.printStackTrace();
}
return plainText;
}
}
* 
The class should be available in the Windchill classpath; for example, <windchill_home>\codebase\com\custom\text\conversion.
After completing the steps given above, the package created will contain description, proposedSolution and reason attributes with simple text values converted from rich text.
Repeat step 2 for all the change objects and rich text attributes that you wish to convert.
Was this helpful?