Skip to main content
1-Visitor
June 9, 2020
Question

Rich text in ESI to SAP

  • June 9, 2020
  • 2 replies
  • 4866 views

Does anyone use rich text on the change notice with ESI sending to SAP?  If so how do you handle the html tags that windchill adds to your description?

2 replies

1-Visitor
June 9, 2020

Hi,

ESI Tibco will not translate any thing. if windchill response file sending html tags, you can pass to SAP as is..

 

regards

GAIN Sreeni

1-Visitor
June 9, 2020

We are using PI/PO and are being told it can not process the html tags.  Are you saying sap can handle the html tags?

1-Visitor
June 9, 2020

Hi

I don't have any idea about SAP PI/PO, but what i'm trying say, if you using ESI then it will work.

if possible share ESI response file if your using ESI services and generation XML file..

 

#gainsreeni

15-Moonstone
May 17, 2023

@gscorpil-2,

I know this is an old post, but https://www.ptc.com/en/support/article/CS312182 addresses this topic partially.

 

Per the SPR, I am told that R&D does not suggest that the extra HTML characters are removed as the downstream system(s) that would receive this information could potentially consume this formatted data.

 

There are two ways this can be solved:

  1. Add some code in an Expression Robot in the workflow template right before the Change Notice hits the Set State Released robot.  The code is pasted below, but the idea is that it copies the plain text version of the rich text description into the original "description" attribute, which is likely not being used in your create/edit/view layouts anymore.  However, at least the plain text description will be stored in the database and shown in the OOTB "description" tag in the ESI output file.  (This is the method I chose.)
  2. Extend ESIECNHeaderRenderer and override adjustElement().  The same java code will be needed: cn.getLongDescription().getPlainText().  In this case you don't need to rely on the code running in the workflow and making a copy of the description (in plain text) in the database.  However, it is a customization and needs to be addressed as such.  (I don't have details since I didn't choose this.)

 

Here is the code for copying the rich text description into the plain text attribute.  As mentioned, this can be dropped into an Execute Expression robot right before the Set State Released node in the Change Notice workflow.  (println statements are just for debugging - you can remove them)

 

if (primaryBusinessObject instanceof wt.change2.WTChangeOrder2) {
 wt.change2.WTChangeOrder2 cn = (wt.change2.WTChangeOrder2)primaryBusinessObject;
 
 String plainTextDescription = cn.getLongDescription().getPlainText();
 System.out.println("The long decription formatted to plain text is: " + plainTextDescription);
 com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(cn, null, null, null);
 obj.load("description");
 
 if (plainTextDescription != null) {
 obj.set("description", plainTextDescription);
 obj.apply();
 System.out.println("applied");
 wt.fc.PersistenceHelper.manager.modify(cn);
 System.out.println("saved (modified)");
 } else {
 System.out.println("plainTextDescription was null");
 }
}

 

5-Regular Member
November 15, 2023

@BenPerry,
This is great, I took it a step further using regex to apply limited formatting so a multi-line description comes out in plaintext as multi-line

JH_9196744_0-1700079229069.png

JH_9196744_1-1700079243787.png

 

 

 

 

if (primaryBusinessObject instanceof wt.change2.WTChangeOrder2) {
 wt.change2.WTChangeOrder2 cn = (wt.change2.WTChangeOrder2)primaryBusinessObject;
 
 String htmlString = cn.getLongDescription().getFormattedText();
 System.out.println("The long decription is: " + htmlString);
 String plainTextDescription = htmlString
 .replaceAll("(?i)<li[^>]*>", "\n- ") // Add a dash and a space before list items
 .replaceAll("(?i)<tr[^>]*>|<td[^>]*>(?!&nbsp;)", "\n") // Newline before table rows and non-empty table data
 .replaceAll("(?i)<p[^>]*>", "\n") // Insert newline before each paragraph tag
 .replaceAll("<[^>]+>", "") // Remove all HTML tags
 .replaceAll("&nbsp;", " ") // Replace HTML non-breaking spaces
 .replaceAll("\n+", "\n").trim(); // Remove multiple newlines and trim whitespace
 System.out.println("The long decription formatted to plain text is: " + plainTextDescription);
 com.ptc.core.lwc.server.PersistableAdapter obj = new com.ptc.core.lwc.server.PersistableAdapter(cn, null, null, null);
 obj.load("description");
 
 if (plainTextDescription != null) {
 obj.set("description", plainTextDescription);
 obj.apply();
 System.out.println("applied");
 wt.fc.PersistenceHelper.manager.modify(cn);
 System.out.println("saved (modified)");
 } else {
 System.out.println("plainTextDescription was null");
 }
}