Maximo Open Forum

 View Only

 How to handle Unicode characters in a Long Description field, when trying to use it in a Comm Template generated from an Automation Script

  • Administration
  • Everything Maximo
Travis Herron's profile image
Travis Herron posted 02-05-2021 11:35
Maximo 7.6.0.8, so Jython 2.5.2

I have a script I wrote that works great almost all of the time.  The basic idea is: We made a Work Order status called TRANSFER.  That's when the team it was assigned to was the totally wrong team.  For example, if a student cannot access their dorm room with their ID card, this could be that his card doesn't have the right access configuration (Security), a hardware failure (Maintenance), or a communication error (IT).  So we might give the Work Order to Maintenance to have a first look at it, he determines it's not a hardware failure, and so passes it to one of the other teams.

Some of those teams don't use Maximo.  When that's the case, my script takes the contents of the Work Order and puts it in an email to the "Help Desk" at that other department/team.  And this all works fine, except when there's a Unicode character in a long description field.  I'm grabbing the Long Description from both the Work Order and, if applicable, the most recent Work Log entry.  So usually these Unicode characters get in there either in the main Long Description from copy-and-pasting from an email that has a contraction or possessive and Outlook turned it into a smart apostrophe; or in the Work Log Long Description if someone uses the iPhone's word suggestions.

Anyways, I don't know what I can do to make it handle Unicode characters.  When it finds one, Maximo throws an error saying it couldn't encode some character at line <whatever>.

Here's the code that grabs the main Long Description:

            if hasLD == 1:

LongDescriptionSet = mbo.getMboSet("LONGDESCRIPTION")
LongDescriptionSet.setQbeExactMatch("true")

if LongDescriptionSet.count() > 0:
LongDescriptionMbo = LongDescriptionSet.getMbo(0)
longDescription = str(LongDescriptionMbo.getString("LDTEXT"))

h_woHead = h_woHead + "<p><b>Details/Additional Comments: </b>" + longDescription + "</p><p></p>"

LongDescriptionSet.setFlag(MboConstants.DISCARDABLE, True)
LongDescriptionSet.close()
How do I get that LDTEXT field to deal with Unicode?  I tried just putting a     u      in front of it, but Maximo wouldn't compile the script.
Biplab Choudhury's profile image
Biplab Choudhury
Hi Travis,

It would be good to see the exact stack trace of the error so that we can understand the exact issue.

Still, as per my understanding of the explained issue , this issue might be coming in the line :
longDescription = str(LongDescriptionMbo.getString("LDTEXT"))
where python is trying to type cast the unicode ldtext to python String.
It could be because of the html content getting copied from email or other sources. This html content type casting could be causing the encoding error in python.
If that is the case then you can try the below 2 resolutions:
https://stackoverflow.com/questions/1061697/whats-the-easiest-way-to-escape-html-in-python
https://stackoverflow.com/questions/2077283/escape-special-html-characters-in-python

Thanks,
Biplab