from psdi.server import MXServer; from psdi.mbo import MboConstants; from java.text import SimpleDateFormat; from java.util import Date import sys; ## Defined function to create a table based upon a child MboSet ## parameter intent: ## source MBO set to loop through ## p_fields [] array that contains the following ## 0 [] array of fields for which data should be pulled, in order, into each cell ## 1 header title (used if table has headers) ## 2 header style (if needing to override default as defined here in function) ## 3 simple date format for date formatting ## 4 desired cell width ## 5 cell style (if needing to override default as defined here in function) ## 6 cell style override (if False, then APPEND) ## 7 PRE-pend string ## 8 POST-pend string ## [[[], header_title, header_style, SDF, cell_width, cell_style]] ## std_header flag to use loop to generate standard header (if true) ## ovr_header flag to use overridden header (passed as a parameter) ## header_override code for overridden header ## table_tags additional tags for the TABLE control ## table_style style for the TABLE control ## empty_table_msg what to display if no content ## link_app app to which link should point ## link_att attribute to be display value for link def create_table(source, p_fields, std_header, ovr_header, header_override, table_tags, table_style, empty_table_msg, link_app, link_att): ## define defaults dflt_cell_style = " padding-left: 5px; padding-right: 5px; background-color: #DDDDDD;"; dflt_head_style = " padding-left: 5px; padding-right: 5px; text-align: center; background-color: #DDDDDD; font-weight: bold;"; dflt_date_SDF = "MM/dd/yyyy"; HTML = ""; ## begin to build s = source.moveFirst(); while (s != None): HTML = HTML + ''; ## start a row for f in p_fields: ## this is the primary loop since fields by column are arrayed... value = ""; for g in f[0]: if (g == "$$LINK$$"): try: value = "" + s.getString(link_att) + ""; except: value = ""; else: try: ## check to see if we have a real field or just need a blank cell... found = s.isNull(g); try: ## check to see if we are dealing w/a date x = s.getDate(g); ## if this succeeds, we're dealing w/a date try: ## see if we have an SDF passed SDF = f[3]; SDF = dflt_date_SDF if SDF == "" else SDF; except: SDF = dflt_date_SDF; value = value + " " + SimpleDateFormat(SDF).format(x); except: value = value + " " + s.getString(g) if value != "" else value + s.getString(g); except: value = " "; try: ## PRE-pend value = str(f[7]) + value; except: value = value; try: ## POST-pend value = value + str(f[8]); except: value = value; try: ## see if we have a cell width defined cell_width = str(f[4]); cell_width = "" if cell_width == "" else " width: " + cell_width + "; "; except: cell_width = ""; try: ## see if we have a cell style defined cell_style = str(f[5]); except: cell_style = dflt_cell_style; try: ## see if cell style should override or append cell_style_override = f[6]; except: cell_style_override = False; cell_style = cell_style if cell_style_override else dflt_cell_style + cell_style; HTML = HTML + '' + value + ''; HTML = HTML + ''; ## end a row s = source.moveNext(); if (source.moveFirst()): ## if we actually have rows in our table, then we need to finalize the HTML... ## build our header if (std_header): header = ""; for f in p_fields: try: header_style = str(f[2]) header_style = dflt_head_style if header_style == "" else header_style; except: header_style = dflt_head_style; try: header = header + '' + f[1] + ''; except: header = header + ' '; header = header + ""; elif (ovr_header): header = header_override; else: header = ""; HTML = '' + header + HTML + '
'; ## finalize the table else: HTML = empty_table_msg; return HTML; def create_multi_table(source, p_fields, p_columns, p_SDF, font_size, font_face, cell_shading, cell_style, table_tags, table_style, empty_table_msg): ## begin to build HTML = ''; ## start a row s = source.moveFirst(); i = 0; while (s != None): if (i%p_columns == 0 and i > 0): HTML = HTML + ""; value = ""; for f in p_fields: ## this is the primary loop since fields by column are arrayed... try: ## check to see if we are dealing w/a date x = s.getDate(f); ## if this succeeds, we're dealing w/a date value = value + " " + SimpleDateFormat(p_SDF).format(x); except: value = value + " " + s.getString(f) if value != "" else value + s.getString(f); HTML = HTML + '' + value + ''; i = i + 1; s = source.moveNext(); if (source.moveFirst()): ## if we actually have rows in our table, then we need to finalize the HTML... HTML = '' + HTML + '
'; ## finalize the table else: HTML = empty_table_msg; return HTML; ## Defined function to create an unnumbered list based upon a child MboSet def create_list(source, p_fields, empty_table_msg): ## begin to build HTML = ""; s = source.moveFirst(); while (s != None): for f in p_fields: ## this is the primary loop since fields by column are arrayed... value = "" # for g in f: # value = value + " " + s.getString(g) if value != "" else value + s.getString(g); value = value + " " + s.getString(f) if value != "" else value + s.getString(f); if (value != ""): HTML = HTML + '
  • ' + value + '
  • '; break; s = source.moveNext(); if (source.moveFirst()): HTML = ''; else: HTML = empty_table_msg; return HTML; ## Defined function to create an unnumbered list based upon a child MboSet def create_csv(source, p_fields, delimiter, empty_table_msg): ## begin to build HTML = ""; s = source.moveFirst(); while (s != None): for f in p_fields: ## this is the primary loop since fields by column are arrayed... value = "" for g in f: value = value + " " + s.getString(g) if value != "" else value + s.getString(g); HTML = HTML + value + delimiter; s = source.moveNext(); if (source.moveFirst()): HTML = HTML[:-len(delimiter)]; else: HTML = empty_table_msg; return HTML; ## Defined function to express a duration in readable format def calcelapsedtime(msdiff): X = msdiff elapsedhours = 0; elapsedminutes = 0; secondinmillis = 1000; minuteinmillis = secondinmillis * 60; hourinmillis = minuteinmillis * 60; dayinmillis = hourinmillis * 24; elapseddays = X / dayinmillis; X = X - elapseddays * dayinmillis; elapsedhours = X / hourinmillis; X = X - elapsedhours * hourinmillis; elapsedminutes = X / minuteinmillis; day_part = str(elapseddays) + " days " if elapseddays > 0 else ""; if (elapsedhours > 0): time_part = str(elapsedhours) + " hours " + str(elapsedminutes) + " minutes"; elif (elapsedminutes > 0): time_part = str(elapsedminutes) + " minutes"; else: time_part = ""; return day_part + time_part; ## script constants SDF_LONG_DATE = "EEEEE, MMMMM dd, yyyy"; SDF_LONG_DATE_TIME = "EEEEE, MMMMM dd, yyyy hh:mm a"; SDF_SHORT_DATE = "MM/dd/yy"; SDF_SHORT_DATE_TIME = "MM/dd/yy hh:mm a"; SDF_SHORT_DATE_TIME_24 = "MM/dd/yy HH:mm"; SDF_SHORT_TIME_DATE_24 = "HH:mm MM/dd/yy"; SDF_TIME = "hh:mm a"; SDF_TIME_24 = "HHmm"; ## figure out our context vServer = MXServer.getMXServer().getRegistryHostName(); ## Figure out our listener e-mail address owner = mbo.getOwner(); owner_name = owner.getName(); try: owner_status = owner.getString("STATUS"); except: owner_status = ""; try: ticket = owner.getMboSet("TICKET").moveFirst(); except: ticket = None; if (vServer[:1].upper() in ("T", "D", "Q")): LISTENER = "qmaxit@max.grenergy.com" INSTANCE = "qmaxtran.grenergy.com" INSTANCE = "tmgeam04:9444" INSTANCE = "maxtraining.grenergy.com" else: LISTENER = "max2252@max.grenergy.com" # INSTANCE = "maxtran.grenergy.com" # # # # # INSTANTIATE ALL VALUES SO WE CAN JUST FIND & REPLACE LATER ON # # # # # ## dates start_date = None; end_date = None; due_date = None; report_date = None; actual_date = None; submitted_date = None; parent_start_date = None; parent_end_date = None; targ_comp_date = None; short_actual_date = ""; long_actual_date = ""; long_start_date = ""; long_end_date = ""; long_due_date = ""; long_start_date_time = ""; long_end_date_time = ""; long_due_date_time = ""; long_parent_start_date = ""; short_start_date = ""; short_end_date = ""; short_due_date = ""; short_start_date_time = ""; short_end_date_time = ""; short_due_date_time = ""; short_submitted_date = ""; short_targcomp_date = ""; start_time = ""; start_time_24 = ""; end_time = ""; end_time_24 = ""; duration = ""; short_report_date = ""; record_age = ""; parent_age = ""; ## Attachments est_doc_links = ""; doc_links = ""; ## myXP table_myxp_piie = ""; table_myxp_owners = ""; table_myxp_actions = ""; csv_myxp_owners = ""; csv_myxp_ownermails = ""; myxp_piie_response = ""; myxp_anonymous = ""; myxp_injuries = ""; myxp_injuries_tr = ""; myxp_piie = ""; myxp_piie_div_dept = ""; myxp_piie_div_dept_fac = ""; myxp_owners = ""; myxp_owners_csv = ""; myxp_owners_emails = ""; myxp_actions = ""; myxp_actions_siblings = ""; myxp_actions_comp = ""; myxp_actions_wappr = ""; myxp_piie_response = ""; myxp_factors_types_record = ""; myxp_action_type = ""; myxp_reappr = ""; parent_tkt_desc = ""; parent_tkt_uid = ""; parent_myxp_cat = ""; ## WO specific fields draft_watermark = ""; revision = ""; multi_poc = ""; multi_eq = ""; multi_parent_poc = ""; multi_parent_eq = ""; gen_ramp_down = ""; gen_ramp_up = ""; gen_ramp_hold = ""; clr_tasks = ""; clr_areas_affected_not = ""; worklog = ""; worklog_parent = ""; related_records = ""; list_wos = ""; list_prc027_wos = ""; ## Change specific fields chg_save_work = ""; chg_contact_2252 = ""; ## Log specific fields log_oid = ""; log_outages = ""; log_relays = ""; log_asst_clr = ""; log_children = ""; ## General items multi_asset_set = None; multi_asset_name = ""; multi_asset_full = ""; list_multi = ""; long_desc = ""; longdesc_br = ""; email_desc = ""; table_parent_worklog = ""; status_color = ""; ## Business Improvement specific fields bi_contributors = ""; bi_divisions = ""; bi_reviewed = ""; ## Ticket specific fields it_survey_responses = ""; # # # # # LONG DESCRIPTION # # # # # try: long_desc = owner.getString("DESCRIPTION_LONGDESCRIPTION"); long_desc = long_desc.replace(chr(10), "
    "); except: long_desc = ""; ## Take care of "DESCRIPTION" field for e-mail links invalid_characters = ["(", ")", "<", ">", "\\", "/", ":", "&", "'", "[", "]", chr(10), chr(13)]; try: email_desc = owner.getString("DESCRIPTION"); for c in invalid_characters: email_desc = email_desc.replace(c, " ", 11L); email_desc = email_desc.decode('utf-8', 'ignore'); email_desc = email_desc.replace("\u2013", "-"); #en dash email_desc = email_desc.replace("\u2014", "--"); #em dash except: email_desc = ""; # # # # # ACTUALLY PULL VALUES, BASED UPON DIFFERENT OBJECTS # # # # # if (owner_name in ("ASSETSPEC")): multi_asset_set = owner.getMboSet("ASSET.ASSETLOCRELATION"); if (owner_name in ("WORKORDER", "WOACTIVITY", "PLUSGACT", "CLR_GRE", "GEN_GRE")): ## work order type records start_date = owner.getDate("ACTSTART"); end_date = owner.getDate("ACTFINISH"); due_date = owner.getDate("FNLCONSTRAINT"); report_date = owner.getDate("REPORTDATE"); targ_comp_date = owner.getDate("TARGCOMPDATE"); ## DRAFT if (owner_status not in ('APPR', 'INPRG', 'COMP', 'POSTPONE')): draft_watermark = "
    ** DRAFT **

    " ## REVISION # try: if (not owner.isNull("CLEAR_REVISION")): revision = " REV #" + owner.getString("CLEAR_REVISION"); except: revision = "" ## Multi-asset multi_asset_set = owner.getMboSet("PMCHGALLTARGETS"); if (owner_name in ("WOCHANGE")): ## work order type records start_date = owner.getDate("TARGSTARTDATE"); end_date = owner.getDate("TARGCOMPDATE"); due_date = owner.getDate("TARGCOMPDATE"); if (owner.getString("PMCHGTYPE") == "Emergency"): chg_save_work = ""; else: chg_save_work = "~ Save all your open work and log out of the affected systems prior to the outage.
    "; chg_contact_2252 = "~ Contact the IT Service Desk at x2252 with questions or concerns.
    "; multi_asset_set = owner.getMboSet("PMCHGALLTARGETS"); if (owner_name in ("ESTIMATE_GRE")): start_date = owner.getDate("ACTSTART"); end_date = owner.getDate("ACTFINISH"); due_date = owner.getDate("TARGETCONTACTDATE_GRE"); if (owner_name in ("PLUSGSHFTLOGENTRY")): start_date = owner.getDate("EVENTDATE"); parent_start_date = owner.getOwner().getDate("STARTDATE"); end_date = owner.getDate("RTNDATE_GRE"); due_date = None; varOID = owner.getString("OID_GRE"); varTKT = owner.getString("TICKETID_GRE"); if (varOID != ""): if (varTKT != ""): # log_oid = '' + varOID + ' -- Ticket #' + varTKT + ''; log_oid = '
    ' + varOID + ' -- Ticket #' + varTKT + '
    '; else: # log_oid = '' + varOID + ''; log_oid = '
    ' + varOID + '
    '; if (owner_name in ("TICKET", "SR", "PROBLEM", "EVENT")): ## ticket type records start_date = owner.getDate("REPORTDATE"); end_date = owner.getDate("ACTUALFINISH"); due_date = owner.getDate("FNLCONSTRAINT_GRE"); report_date = owner.getDate("REPORTDATE"); submitted_date = owner.getDate("PLUSGINITDATE"); actual_date = owner.getDate("AFFECTEDDATE"); if (owner.getBoolean("ANONYMOUS_GRE")): myxp_anonymous = " ANONYMOUS "; ## Multi-asset multi_asset_set = owner.getMboSet("ALLMULTIASSETLOCCI"); ## myExperience reapproval myxp_reappr = owner.getString("NP_STATUSMEMO"); if (myxp_reappr != ""): myxp_reappr = "NOTE--this myExperience event has been revised and resubmitted for approval with the following reason: " + myxp_reappr.upper() + ""; if (owner_name in ("PLUSGINCPERSON")): try: status = owner.getString("STATUS_GRE"); comments = owner.getString("STATUS_COMMENT_GRE"); except: status = ""; comments = "" if (status == "REJECTED"): if (comments != ""): comments = " with the following comments: " + comments; myxp_piie_response = "REJECTED" + comments; if (status == "APPROVED" and comments == ""): myxp_piie_response = "APPROVED"; if (status == "APPROVED" and comments != ""): if (comments != ""): comments = " with suggested changes or comments: " + comments; myxp_piie_response = "APPROVED" + comments; # # # # # DO VARIOUS PROCESSING # # # # # ## Various date formats... if (parent_start_date): long_parent_start_date = SimpleDateFormat(SDF_LONG_DATE).format(start_date); if (start_date): long_start_date = SimpleDateFormat(SDF_LONG_DATE).format(start_date); long_start_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(start_date); short_start_date = SimpleDateFormat(SDF_SHORT_DATE).format(start_date); short_start_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(start_date); start_time = SimpleDateFormat(SDF_TIME).format(start_date); start_time_24 = SimpleDateFormat(SDF_TIME_24).format(start_date); if (end_date): long_end_date = SimpleDateFormat(SDF_LONG_DATE).format(end_date); long_end_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(end_date); short_end_date = SimpleDateFormat(SDF_SHORT_DATE).format(end_date); short_end_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(end_date); end_time = SimpleDateFormat(SDF_TIME).format(end_date); end_time_24 = SimpleDateFormat(SDF_TIME_24).format(end_date); if (due_date): long_due_date = SimpleDateFormat(SDF_LONG_DATE).format(due_date); long_due_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(due_date); short_due_date = SimpleDateFormat(SDF_SHORT_DATE).format(due_date); short_due_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(due_date); else: long_due_date = "-- no due date specified --"; long_due_date_time = "-- no due date specified --"; short_due_date = "-- no due date specified --"; short_due_date_time = "-- no due date specified --"; if (report_date): short_report_date = SimpleDateFormat(SDF_SHORT_DATE).format(report_date); if (actual_date): short_actual_date = SimpleDateFormat(SDF_SHORT_DATE).format(actual_date); long_actual_date = SimpleDateFormat(SDF_LONG_DATE_TIME).format(actual_date); if (submitted_date): short_submitted_date = SimpleDateFormat(SDF_SHORT_DATE).format(submitted_date); if (targ_comp_date): short_targcomp_date = SimpleDateFormat(SDF_SHORT_DATE).format(targ_comp_date); ## Finalize duration processing if (start_date != None and end_date != None): timediff = end_date.getTime() - start_date.getTime(); duration = calcelapsedtime(timediff); elif (start_date != None): duration = "ONGOING"; elif (start_date == None and end_date == None): duration = "NOT STARTED"; else: duration = ""; ## Age calculation try: timediff = (MXServer.getMXServer().getDate().getTime() - report_date.getTime()) / 86400000; record_age = calcelapsedtime(timediff); except: record_age = ""; if (owner_name in ("WOSTATUS")): varx = owner.getOwner().getString("PLUSGACTIONTYPE"); if (varx != ""): myxp_action_type = varx.lower() + " action"; if (owner_name in ("WOACTIVITY", "PLUSGACT")): varx = owner.getString("PLUSGACTIONTYPE"); if (varx != ""): myxp_action_type = varx.lower() + " action"; try: act_parent = owner.getMboSet("PARENT").moveFirst(); act_ticket = owner.getMboSet("TICKET").moveFirst() if (act_parent): timediff = MXServer.getMXServer().getDate().getTime() - act_parent.getDate("REPORTDATE").getTime(); parent_age = calcelapsedtime(timediff); elif (act_ticket): timediff = MXServer.getMXServer().getDate().getTime() - act_ticket.getDate("REPORTDATE").getTime(); parent_age = calcelapsedtime(timediff); else: parent_age = ""; except: parent_age = ""; ## Color code STATUS try: owner_status = owner.getString("STATUS"); sl = int((10 - len(owner_status)) / 2); ## figure out padding sx = ""; for i in range(0,sl): sx = sx + " "; if (owner_status == "REGISTERED"): status_color = "" + sx + owner_status + sx + ""; elif (owner_status == "SUBMITTED"): status_color = "" + owner_status + ""; elif (owner_status == "APPR"): status_color = "" + sx + owner_status + sx + ""; elif (owner_status == "INPRG"): status_color = "" + sx + owner_status + sx + ""; elif (owner_status == "COMP"): status_color = "" + sx + owner_status + sx + ""; elif (owner_status in ("CAN", "POSTPONED")): status_color = "" + sx + owner_status + sx + ""; elif (owner_status == "DENIED"): status_color = "" + sx + owner_status + sx + ""; else: status_color = owner_status; except: status_color = ""; ## Attachments try: set = owner.getMboSet("DOCLINKS"); set.setOrderBy("ESTDOCTYPE_GRE"); set.reset(); flag = 0; s = set.moveFirst(); while (s): est_doc_links = est_doc_links + "" + s.getString("ESTDOCTYPE_GRE.DESCRIPTION") + ""; doc_links = doc_links + "" + s.getString("DOCINFO.DESCRIPTION") + ""; flag = 1; s = set.moveNext(); est_doc_links = "" + est_doc_links + "
    " if flag else ""; doc_links = "" + doc_links + "
    " if flag else ""; except: est_doc_links = ""; doc_links = ""; ## Multi Assets try: if (multi_asset_set): multi_asset_name = create_list(multi_asset_set, ["ASSET.NAME.ALNVALUE"], "-- no assets listed --"); multi_asset_full = create_list(multi_asset_set, ["ASSETNUM", "DESCRIPTION", "STATUS"], "-- no assets listed --"); except: multi_asset_name = ""; multi_asset_full = ""; try: list_multi = create_csv(multi_asset_set, [["ASSET.DESCRIPTION"]], ", ", "-- no targets designated --"); except: list_multi = ""; ## myExperience if (owner_name in ("PROBLEM", "EVENT")): myxp_piie = create_table(owner.getMboSet("MYXP_PIIE"), [[["PERSON.FIRSTNAME", "PERSON.LASTNAME"], "Involved Party"], [["DIVISION.DESCRIPTION"], "GRE Division"]], True, False, "", "", "", "-- no involved parties --", "", ""); myxp_piie_div_dept = create_table(owner.getMboSet("MYXP_PIIE"), [[["DIVISION.DESCRIPTION"], "GRE Division"], [["DEPARTMENT.DESCRIPTION"], "Department"]], True, False, "", "", "", "-- no involved parties --", "", ""); myxp_piie_div_dept_fac = create_table(owner.getMboSet("MYXP_PIIE"), [[["DIVISION.DESCRIPTION"], "Employee Division"], [["DEPARTMENT.DESCRIPTION"], "Employee Department"], [["LOCATION.DESCRIPTION"], "Employee Facility"]], True, False, "", "", "", "-- no involved parties --", "", ""); myxp_injuries = create_table(owner.getMboSet("MYXP_INJURIES"), [[["PERSON.DIVISION.DESCRIPTION"], "Employee Division"], [["LOCATION.DESCRIPTION"], "Injury Location"]], True, False, "", "", "", "-- no injuries --", "", ""); myxp_injuries_tr = create_table(owner.getMboSet("MYXP_TR_INJURIES"), [[["INJORILLDATE"], "Date of Injury / Illness", "", SDF_SHORT_DATE_TIME], [["LOCATION.DESCRIPTION"], "Injury Location"]], True, False, "", "", "", "-- no injuries --", "", ""); myxp_factors_types_record = create_table(owner.getMboSet("MYXP_V_HFRESULTS_RECORD"), [[["FACTOR_DESCRIPTION"], "Factor"], [["TYPE_DESCRIPTION"], "Type"]], True, False, "", "", "", "-- no factors / types --", "", ""); ## actions action_set = owner.getMboSet("SHOWTASKS_GRE"); action_set.setOrderBy("WOSEQUENCE"); action_set.reset(); myxp_actions = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --", "", ""); action_set = owner.getMboSet("MYXP_ACTIONS_REAL"); action_set.setOrderBy("WOSEQUENCE"); action_set.reset(); myxp_actions_comp = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --", "", ""); action_set = owner.getMboSet("MYXP_ACTIONS_WAPPR"); action_set.setOrderBy("WOSEQUENCE"); action_set.reset(); myxp_actions_wappr = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --", "", ""); ## WORK ORDER TYPE RECORDS if (owner_name in ("PLUSGRCFARESULTS", "PLUSGACT", "PROBLEM", "EVENT", "WOOWNERHISTORY", "WOACTIVITY", "WORKORDER")): myxp_owners = create_table(owner.getMboSet("MYXP_OWNERS"), [[["PERSON.FIRSTNAME", "PERSON.LASTNAME"], "Owner"], [["DIVISION.DESCRIPTION"], "GRE Division"], [["PHONE"], "Phone #"], [["EMAIL"], "E-mail"]], True, False, "", "", "", "-- no owners designated --", "", ""); myxp_owners_csv = create_csv(owner.getMboSet("MYXP_OWNERS"), [["PERSON.FIRSTNAME", "PERSON.LASTNAME"]], ", ", "-- no owners designated --"); myxp_owners_emails = create_csv(owner.getMboSet("MYXP_OWNERS"), [["PERSON.PRIMARYEMAIL"]], "; ", ""); if (owner_name in ("PLUSGACT")): ## actions action_set = owner.getMboSet("MYXP_SIBLINGS"); action_set.setOrderBy("WOSEQUENCE"); action_set.reset(); myxp_actions_siblings = create_table(action_set, [[["$$LINK$$"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --", "myxp_act", "WONUM"); if (owner_name in ("WORKORDER", "WOACTIVITY", "PLUSGACT", "CLR_GRE", "GEN_GRE")): ## work order type records ## General list_wos = create_table(owner.getThisMboSet(), [[["WONUM"], "WO #"], [["DESCRIPTION"], "Description"], [["STATUS"], "Status"]], True, False, "", "", "", "", "", ""); # list_prc027_wos = create_table(owner.getMboSet("REL_PRC027_WOS"), [[["RELATEDRECKEY"], "WO #"], [["RELATEDRECWO.DESCRIPTION"], "Description"], [["RELATEDRECWO.JPNUM"], "Job Plan"]], True, False, "", "", "", "", "", ""); list_prc027_wos = create_table(owner.getMboSet("REL_PRC027_WOS"), [[["WONUM"], "WO #"], [["DESCRIPTION"], "Description"], [["JPNUM"], "Job Plan"]], True, False, "", "", "", "", "", ""); ## Multi-asset multi_poc = create_table(owner.getMboSet("POC"), [[["COMMENTS"], "LOCATION", "background-color: #666699;", "", "25%", "color: #FFFFFF;"], [["CKT_POS_LOC_GRE"], "DEVICE", "background-color: #666699;", "", "25%", "color: #FFFFFF;"], [["TARGETDESC"], "DEVICE DESCRIPTION", "background-color: #666699;", "", "50%", "color: #FFFFFF;"]], True, True, "", "", "width: 100%;", "-- no points of clearance designated --", "", ""); multi_eq = create_table(owner.getMboSet("EQUIPMENT"), [[["COMMENTS"], "LOCATION", "background-color: #666699;", "", "25%", "color: #FFFFFF;"], [["CKT_POS_LOC_GRE"], "DEVICE", "background-color: #666699;", "", "25%", "color: #FFFFFF;"], [["TARGETDESC"], "DEVICE DESCRIPTION", "background-color: #666699;", "", "50%", "color: #FFFFFF;"]], True, True, "", "", "width: 100%;", "-- no affected equipment designated --", "", ""); multi_parent_poc = create_table(owner.getMboSet("PARENT.POC"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no points of clearance designated --", "", ""); multi_parent_eq = create_table(owner.getMboSet("PARENT.EQUIPMENT"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no affected equipment designated --", "", ""); ## Tasks task_set = owner.getMboSet("SHOWTASKS_GRE"); task_set.setOrderBy("WOSEQUENCE"); task_set.reset(); clr_tasks = create_table(task_set, [[[""], "", "", "", "15%"], [["WOSEQUENCE"], "", "", "", "10%", "text-align: center;", False], [["DESCRIPTION", "DESCRIPTION_LONGDESCRIPTION"], "", "", "", "75%"]], False, True, "", "", "", "-- no switching steps defined --", "", ""); ## Work Log wl_set = owner.getMboSet("GRE_MODIFYWORKLOG"); wl_set.setOrderBy("WORKDATE_GRE"); wl_set.reset(); worklog = create_table(wl_set, [[["WORKDATE_GRE"], "Date", "", SDF_SHORT_DATE, "15%", "text-align: center;", False], [["DESCRIPTION"], "Remark", "", "", "85%"]], True, False, "", "", "", "No remarks recorded", "", ""); wl_set = owner.getMboSet("PARENT.GRE_MODIFYWORKLOG"); wl_set.setOrderBy("WORKDATE_GRE"); wl_set.reset(); worklog_parent = create_table(wl_set, [[["WORKDATE_GRE"], "Date", "", SDF_SHORT_DATE, "15%", "text-align: center;", False], [["DESCRIPTION"], "Remark", "", "", "85%"]], True, False, "", "", "", "", "", ""); ## Generation ramp points gen_set = owner.getMboSet("GEN_RAMPDOWN"); gen_set.setOrderBy("SEQUENCE"); gen_set.reset(); gen_ramp_down = create_table(gen_set, [[["ENDDATE"], "START"], [["STARTDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW/hr"]], True, False, "", "", "", "-- no ramp down points recorded --", "", ""); gen_set = owner.getMboSet("GEN_RAMPUP"); gen_set.setOrderBy("SEQUENCE"); gen_set.reset(); gen_ramp_up = create_table(gen_set, [[["STARTDATE"], "START"], [["ENDDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW/hr"]], True, False, "", "", "", "-- no ramp up points recorded --", "", ""); gen_set = owner.getMboSet("GEN_HOLD"); gen_set.setOrderBy("SEQUENCE"); gen_set.reset(); gen_ramp_hold = create_table(gen_set, [[["STARTDATE"], "START"], [["ENDDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW"]], True, False, "", "", "", "-- no ramp hold points recorded --", "", ""); ## Areas affected aa_set = owner.getMboSet("WO_AREASAFFECTED_NOT"); aa_set.setOrderBy("CONTACTDATE_GRE DESC"); aa_set.reset(); clr_areas_affected_not = create_multi_table(aa_set, ["CONTACT.FIRSTNAME", "CONTACT.LASTNAME", "CONTACTDATE_GRE"], 4, SDF_SHORT_DATE, "2", "courier", "#DDDDDD", "", "", "", "-- no notification entries specified --"); ## Related Records try: rel_set = owner.getMboSet("RELATEDWO"); rel_set.setOrderBy("RECORDKEY"); rel_set.reset(); if (rel_set.moveFirst()): r = rel_set.moveFirst(); while (r): if (r.getString("RELATEDRECWO.CLR_GRE.CLEAR_TYPE") != ""): varX = "Clearance #"; elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "OUTAGE"): varX = "Outage #"; elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "DERATE"): varX = "Outage #"; elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "TEST"): varX = "Outage #"; else: varX = "Work Order #"; related_records = related_records + '' + varX + " " + cm.getString("RELATEDRECKEY") + '' + cm.getString("RELATEDRECWO.DESCRIPTION") + '' r = rel_set.moveNext(); except: varX = ""; try: rel_set = owner.getMboSet("RELATEDTICKET"); rel_set.setOrderBy("RECORDKEY"); rel_set.reset(); if (rel_set.moveFirst()): r = rel_set.moveFirst(); while (r): related_records = related_records + 'Ticket # ' + r.getString("RELATEDRECKEY") + '' + r.getString("RELATEDRECWO.DESCRIPTION") + '' r = rel_set.moveNext(); if (related_records != ""): related_records = '' + related_records + '
    '; else: related_records = "
    "; except: related_records = ""; if (owner_name in ("PLUSGSHFTLOGENTRY")): log_type = owner.getString("LOGTYPE"); ## relays if (log_type in ("EVENT", "DIST", "BUS")): oset = owner.getMboSet("OUTAGE_BREAKERS"); oset.setOrderBy("ACTUALSTART"); oset.reset(); log_relays = create_table(oset, [[["LOCATION.GENERICNAME.ALNVALUE"], "", "", "", "20%", "border: 1px solid black;", False], [["DESCRIPTION"], "", "", "", "80%", "border: 1px solid black;", False]], True, False, "", "", "", "-- no relay operations --", "", ""); log_relays = '
    Relay Information
    ' + log_relays + '
    '; else: log_relays = ""; ## children oset = owner.getMboSet("CHILD_NO_CLR"); oset.setOrderBy("EVENTDATE"); oset.reset(); log_children = create_table(oset, [[["EVENTDATE"], "", "", SDF_SHORT_DATE_TIME_24, "20%", "text-align: center; border: 1px solid black; background-color: #a9d1ff; ", True], [["DESCRIPTION"], "", "", "", "80%", "border: 1px solid black;", False]], True, False, "", "", "width: 100%;", "", "", ""); ## outages if (log_type in ("EVENT", "BUS")): oset = owner.getMboSet("OUTAGE_SUBS"); oset.setOrderBy("ACTUALSTART"); oset.reset(); log_outages = create_table(oset, [[["ASSET.DESCRIPTION"], "", "", "", "60%", "border: 1px solid black; background-color: #ffffdb; ", False], [["ACTUALSTART"], "", "", SDF_SHORT_TIME_DATE_24, "10%", "text-align: center; border: 1px solid black;", False], [["ACTUALFINISH"], "", "", SDF_SHORT_TIME_DATE_24, "10%", "text-align: center; border: 1px solid black;", False], [["OUTAGEDURATION"], "", "", "", "20%", "text-align: center; border: 1px solid black; background-color: #c0c0c0; ", False, "DURATION:
    ", ""]], True, False, "", "", "", "-- no distribution substation outages --", "", ""); log_outages = '
    Distribution Substation Outages
    ' + log_outages + '
    '; else: log_outages = ""; ## associated clearances oset = owner.getMboSet("CHILD_ASST_CLR"); oset.setOrderBy("TOANUM_GRE"); oset.reset(); o = oset.moveFirst(); while (o): varE = SimpleDateFormat(SDF_SHORT_TIME_DATE_24).format(o.getDate("EVENTDATE")); if (o.getString("TOANUM_GRE.ACTSTART") != ""): varE = SimpleDateFormat(SDF_SHORT_TIME_DATE_24).format(o.getDate("TOANUM_GRE.ACTSTART")); if (o.getString("TOANUM_GRE.ACTSTART") == ""): varD = "NOT STARTED"; varF = ""; elif (o.getString("TOANUM_GRE.ACTFINISH") == ""): varD = "ONGOING"; varF = ""; else: timediff = o.getDate("TOANUM_GRE.ACTFINISH").getTime() - o.getDate("TOANUM_GRE.ACTSTART").getTime() timespent = calcelapsedtime(timediff) varD = timespent; varF = SimpleDateFormat(SDF_SHORT_TIME_DATE_24).format(o.getDate("TOANUM_GRE.ACTFINISH")); varL = "Clearance #" + o.getString("TOANUM_GRE"); if (o.getString("TOANUM_GRE.SCHEDSTART") != ""): start_date = SimpleDateFormat("MM/dd/yy").format(o.getDate("TOANUM_GRE.SCHEDSTART")); start_time = SimpleDateFormat("HH:mm").format(o.getDate("TOANUM_GRE.SCHEDSTART")); else: start_date = ""; start_time = ""; if (o.getString("TOANUM_GRE.SCHEDFINISH") != ""): end_date = SimpleDateFormat("MM/dd/yy").format(o.getDate("TOANUM_GRE.SCHEDFINISH")); end_time = SimpleDateFormat("HH:mm").format(o.getDate("TOANUM_GRE.SCHEDFINISH")); else: end_date = ""; end_time = ""; varLS = "Scheduled: " + start_date + " " + start_time + " to " + end_date + " " + end_time; log_asst_clr = log_asst_clr + '' + varL + '' + o.getString("TOANUM_GRE.DESCRIPTION") + '

    ' + varLS + '
    ' + varE + '' + varF + 'DURATION: ' + varD + ''; o = oset.moveNext(); if (log_asst_clr != ""): log_asst_clr = '
    ' + log_asst_clr + '
    Associated Clearances
    '; ## Ticket Type Fields ## try: TKT = owner.getMboSet("TICKET").moveFirst() if owner.getMboSet("TICKET").moveFirst() != None else owner.getOwner(); parent_tkt_desc = TKT.getString("DESCRIPTION"); parent_tkt_uid = str(TKT.getLong("TICKETUID")); parent_myxp_cat = TKT.getString("PLUSGINVESTTYPE"); except: x = 1; ## Get values for business improvements if (owner_name == "BUSIMP_GRE"): if (owner.getBoolean("REVIEWED")): bi_reviewed = "YES"; else: bi_reviewed = "NO"; bi_contributors = create_list(owner.getMboSet("WO_PERSONS_GRE"), ["PERSON.DISPLAYNAME"], "No contributors listed..."); bi_divisions = create_list(owner.getMboSet("BIDIVISIONS"), ["DIVISION.DESCRIPTION"], "No divisions listed..."); x = 1; ## Get values for tickets if (owner_name == "ITSD_SURVEYS_GRE"): html = ""; # # # # # DO THE ACTUAL REPLACEMENTS # # # # # ## Context MSG = mbo.getString("MESSAGE"); MSG = MSG.replace("#LISTENER#", LISTENER); MSG = MSG.replace("#INSTANCE#", INSTANCE); ## Records MSG = MSG.replace("#EST_DOCLINKS#", est_doc_links); MSG = MSG.replace("#LIST_MULTI#", list_multi); ## Dates MSG = MSG.replace("#LONG_PARENT_START_DATE#", long_parent_start_date); MSG = MSG.replace("#LONG_START_DATE_TIME#", long_start_date_time); MSG = MSG.replace("#LONG_END_DATE_TIME#", long_end_date_time); MSG = MSG.replace("#SHORT_DUE_DATE#", short_due_date); MSG = MSG.replace("#SHORT_DUE_DATE_TIME#", short_due_date_time); MSG = MSG.replace("#LONG_DUE_DATE#", long_due_date); MSG = MSG.replace("#LONG_DUE_DATE_TIME#", long_due_date_time); MSG = MSG.replace("#DURATION#", duration); MSG = MSG.replace("#AGE#", record_age); MSG = MSG.replace("#PARENT_AGE#", parent_age); MSG = MSG.replace("#SHORT_REPORT_DATE#", short_report_date); MSG = MSG.replace("#LONG_ACTUAL_DATE#", long_actual_date); MSG = MSG.replace("#SHORT_ACTUAL_DATE#", short_actual_date); MSG = MSG.replace("#SHORT_SUBMITTED_DATE#", short_submitted_date); MSG = MSG.replace("#START_TIME_24#", start_time_24); MSG = MSG.replace("#END_TIME_24#", end_time_24); MSG = MSG.replace("#SHORT_END_DATE#", short_end_date); MSG = MSG.replace("#SHORT_TARGCOMP_DATE#", short_targcomp_date); ## myXP MSG = MSG.replace("#MYXP_PIIE#", myxp_piie); MSG = MSG.replace("#MYXP_PIIE_DIV_DEPT#", myxp_piie_div_dept); MSG = MSG.replace("#MYXP_PIIE_DIV_DEPT_FAC#", myxp_piie_div_dept_fac); MSG = MSG.replace("#MYXP_OWNERS#", myxp_owners); MSG = MSG.replace("#MYXP_OWNERS_CSV#", myxp_owners_csv); MSG = MSG.replace("#MYXP_OWNERS_EMAILS#", myxp_owners_emails); MSG = MSG.replace("#MYXP_INJURIES#", myxp_injuries); MSG = MSG.replace("#MYXP_TR_INJURIES#", myxp_injuries_tr); MSG = MSG.replace("#MYXP_PIIE_RESPONSE#", myxp_piie_response); MSG = MSG.replace("#MYXP_ANONYMOUS#", myxp_anonymous); MSG = MSG.replace("#MYXP_ACTIONS#", myxp_actions); MSG = MSG.replace("#MYXP_ACTIONS_SIBLINGS#", myxp_actions_siblings); MSG = MSG.replace("#MYXP_ACTIONS_COMP#", myxp_actions_comp); MSG = MSG.replace("#MYXP_ACTIONS_WAPPR#", myxp_actions_wappr); MSG = MSG.replace("#MYXP_PIIE_RESPONSE#", myxp_piie_response); MSG = MSG.replace("#MYXP_FACTORS_TYPES_RECORD#", myxp_factors_types_record); MSG = MSG.replace("#ACTION_TYPE#", myxp_action_type); MSG = MSG.replace("#PARENT_MYXP_CAT#", parent_myxp_cat); MSG = MSG.replace("#MYXP_REAPPR#", myxp_reappr); ## Clearance MSG = MSG.replace("#REV#", revision); MSG = MSG.replace("#STATUS#", status_color); MSG = MSG.replace("#AFFECTED_ASSETS#", multi_eq); MSG = MSG.replace("#POC#", multi_poc); MSG = MSG.replace("#PARENT_POC#", multi_parent_poc); MSG = MSG.replace("#PARENT_EQ#", multi_parent_eq); MSG = MSG.replace("#AREAS_AFFECTED#", clr_areas_affected_not); ## Change MSG = MSG.replace("#CHG_SAVE_WORK#", chg_save_work); MSG = MSG.replace("#CHG_CONTACT_2252#", chg_contact_2252); ## Log entries MSG = MSG.replace("#LOG_OID#", log_oid); MSG = MSG.replace("#LOG_ASST_CLR#", log_asst_clr); MSG = MSG.replace("#LOG_CHILDREN#", log_children); MSG = MSG.replace("#LOG_RELAYS#", log_relays); MSG = MSG.replace("#LOG_OUTAGES#", log_outages); ## General MSG = MSG.replace("#PARENT_TKT_DESC#", parent_tkt_desc); MSG = MSG.replace("#PARENT_TKT_UID#", parent_tkt_uid); MSG = MSG.replace("#LONG_DESC#", long_desc); MSG = MSG.replace("#MULTI_ASSET#", multi_asset_name); MSG = MSG.replace("#MULTI_ASSET_FULL#", multi_asset_full); MSG = MSG.replace("#AREAS_AFFECTED_NOT#", clr_areas_affected_not); MSG = MSG.replace("#CLR_SWITCHING#", clr_tasks); MSG = MSG.replace("#WORKLOG#", worklog); MSG = MSG.replace("#WORKLOG_PARENT#", worklog_parent); MSG = MSG.replace("#LIST_WOS#", list_wos); MSG = MSG.replace("#REL_PRC027_WOS#", list_prc027_wos); MSG = MSG.replace("#DESC_EMAIL#", email_desc); MSG = MSG.replace("#LONGDESC_BR#", longdesc_br); ## Business Improvement MSG = MSG.replace("#BI_CONTRIBUTORS#", bi_contributors); MSG = MSG.replace("#BI_DIVISIONS#", bi_divisions); MSG = MSG.replace("#BI_REVIEWED#", bi_reviewed); MSG = MSG.replace("#ATTACHMENTS#", doc_links); ## Ticket MSG = MSG.replace("#IT_SURVEY_RESPONSES#", it_survey_responses); ## process any HTML long description requests while (MSG.find("$$LDHTML$$") != -1): st_loc = MSG.find("$$LDHTML$$"); en_loc = MSG.find("@@LDHTML@@"); snippet = MSG[st_loc:en_loc + 10]; snippet = snippet.replace(chr(10), "
    "); snippet = snippet.replace("$$LDHTML$$", ""); snippet = snippet.replace("@@LDHTML@@", ""); MSG = MSG[:st_loc] + snippet + MSG[en_loc + 10:]; mbo.setValue("MESSAGE", MSG, 11L);