I have rows in a database table with a hierarchypath column. The values in the column are hierarchy paths with up to four levels:
HIERARCHYPATH
---------------------------------------------------
FACILITIES \ FIREHALL \ PLUMBING
FACILITIES \ PARK
ROADS \ GRASS/TURF BLVD MAINTENANCE
ROADS \ SIDEWALKS \ REPLACEMENT
FACILITIES \ PARKING - MAIN ST
RECREATION \ BANDSHELL \ PROPERTY \ BUILDING-GENERAL
FACILITIES
I've written a Jython 2.7 automation script that parses the levels at the \ delimiter and inserts the values into individual level columns:
- CLASSL1
- CLASSL2
- CLASSL3
- CLASSL4
#Example:
s = "FACILITIES \ FIREHALL \ PLUMBING"
col_prefix = "CLASSL"
#Note: The term "mbo" is an IBM Maximo concept.
#It can be thought of as the currently selected record in the application.
for i in range(0, 4):
try:
mbo.setValue(col_prefix + str(i+1), s.split(' \\ ')[i])
except:
#Null-out any existing values that were not overriden
mbo.setValueNull(col_prefix + str(i+1))
HIERARCHYPATH CLASSL1 CLASSL2 CLASSL3 CLASSL4
-------------------------------- ---------- ---------- ---------- -----------
FACILITIES \ FIREHALL \ PLUMBING FACILITIES FIREHALL PLUMBING null
I'm relatively new to coding. How can the script be improved?