Friday 2 September 2022

Maximo Script to Remove HTML Tags Using Regular Expression

 There are times when you need to send long description to external system. But the problem occurs when the Long Description is rich text enabled and contains html tags. Below script uses regular expression to remove the HTML tags.

print ("***********Start of the Script************")
from java.util.regex import Pattern
item_long = mbo.getString("DESCRIPTION_LONGDESCRIPTION")
print (item_long)
match_v1 = Pattern.compile('\\<.*?\\>').matcher(item_long).replaceAll('')
print (match_v1)
print ("************End of the Script**************")

Result

**********Start of the Script************
<div>dasdasd</div><div>sdasd </div><div>asdasd </div><div>asdasdasd </div><div>sdasdas <br /></div><!-- RICH TEXT -->
dasdasdsdasd asdasd asdasdasd sdasdas 
************End of the Script**************

Thursday 30 June 2022

Maximo Attachment File Size

 Below is the script to calculate the Attachment size in Maximo. The File class is used to get the File details and Length() method is used to capture the size details.

from java.io import File 

path = mbo.getString("DOCLINKS.DOCINFO.URLNAME")
print("The Path Value:",path)
if (path):
	file =  File(path)
	print("The Size of the File in Bytes",file.length())
	print("The Size of the File in MB",file.length()/1024)
	print("The Size of the File in GB",file.length()/(1024 * 1024))
Below is the output captured in the system logs.
[6/30/22 8:01:53:951 EDT] 000000e2 SystemOut     O 30 Jun 2022 08:01:53:951 [INFO] [MXServer] [] ('The Path Value:', u'c:\\DOCLINKS\\ATTACHMENTS\\Maximo-access-via-Published-Service-in-your-local-laptop-browser.docx')
('The Size of the File in Bytes', 543667L)
('The Size of the File in MB', 530L)
('The Size of the File in GB', 0L)