Maximo List Archive

This is an archive of the Maximo Yahoo Community. The content of this pages may be a sometimes obsolete so please check post dates.
Thanks to the community owner Christopher Wanko for providing the content.



Run Report Within Automation Script

From: Ian Turner (2016-06-07 17:13)

Can anyone tell us how to attach a Birt report to an email within an
automation script? We are able to produce the blank template but there is no
content:

<script>

from java.util import Calendar
from java.util import Date
from psdi.app.report import ReportUtil
from psdi.server import MXServer
from psdi.mbo import MboConstants
from psdi.mbo import SqlFormat
from com.ibm.tivoli.maximo.report.birt.admin import ReportAdminServiceRemote
from com.ibm.tivoli.maximo.report.birt.runtime import
ReportExecutionParameterData

if str (v_reportname) is None:
print "Report name not supplied to script, exiting"
sys.exit(0)

print "WORKORDER status old value: " + str(v_status_initial)
print "WORKORDER status new value: " + str(v_status)

if (str(v_status) != str(v_status_initial)) and v_status=='APPR':
print "Status change is happening from " + str(v_status_initial) + "
to " + str (v_status)
# set a schedule for the report
c = Calendar.getInstance()
# add 60 seconds to current time to allow preparing REPORTSCHED cron
task instance
c.add(Calendar.SECOND,30)
d = c.getTime()
thisposet = mbo.getThisMboSet()
if thisposet is not None:
locale = thisposet.getClientLocale()
userinfo = thisposet.getUserInfo()
schedule =
ReportUtil.convertOnceToSchedule(d,locale,c.getTimeZone())
print "Schedule we have to set into REPORTSCHED Cron task is: " +
str(schedule)
if schedule is not None:
reportschedset =
MXServer.getMXServer().getMboSet("REPORTSCHED",userinfo)
if reportschedset is not None:
print "Obtained REPORTSCHED set"
reportsched = reportschedset.add()
reportsched.setValue("REPORTNAME",v_reportname)
reportsched.setValue ("appname",v_appname)
reportsched.setValue
("USERID",userinfo.getUserName())
reportsched.setValue ("TYPE","once")
reportsched.setValue("EMAILTYPE",v_emailtype)
reportsched.setValue("MAXIMOURL",v_maximourl)
reportsched.setValue("EMAILUSERS",v_emailto)
reportsched.setValue("EMAILSUBJECT",v_emailsubject)

reportsched.setValue("EMAILCOMMENTS",v_emailcomments)

reportsched.setValue("EMAILFILETYPE",v_emailfiletype)
reportsched.setValue("COUNTRY",locale.getCountry())

reportsched.setValue("LANGUAGE",locale.getLanguage())
reportsched.setValue("VARIANT",locale.getVariant())

reportsched.setValue("TIMEZONE",thisposet.getClientTimeZone().getID())

reportsched.setValue("LANGCODE",userinfo.getLangCode())
woSet =
MXServer.getMXServer().getMboSet("WORKORDER",userinfo)
print "About to work with REPORTSCHEDULE cron task"
crontaskdef =
reportsched.getMboSet("$parent","crontaskdef","crontaskname='REPORTSCHEDULE'
").getMbo(0)
if crontaskdef is not None:
crontaskinstset =
crontaskdef.getMboSet("CRONTASKINSTANCE")
if crontaskinstset is not None:
print "About to work with Cron task
instance of REPORTSCHEDULE cron task"
crontaskinst =
crontaskinstset.add(MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if crontaskinst is not None:
d = Date()
crontaskinstname =
str(d.getTime())

crontaskinst.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSC
HECK | MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("INSTANCENAME",crontaskinstname,MboConstants.NOACCESSC
HECK | MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("SCHEDULE",schedule,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("ACTIVE",1,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("RUNASUSERID",userinfo.getUserName(),MboConstants.NOAC
CESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("HASLD",0,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)

crontaskinst.setValue("AUTOREMOVAL",True,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
print "have set all cron
task instance values for REPORTSCHEDULE cron task"

reportsched.setValue("CRONTASKNAME",crontaskinst.getString("CRONTASKNAME"))

reportsched.setValue("INSTANCENAME",crontaskinst.getString("INSTANCENAME"))
print "Now going to work with Cron task PARAMETERS"
cronparamset = crontaskinst.getMboSet("PARAMETER")
if cronparamset is not None:
sqf =
SqlFormat(cronparamset.getUserInfo(),"reportname=:1")

sqf.setObject(1,"REPORTPARAM","REPORTNAME",v_reportname)
reportparamset =
MXServer.getMXServer().getMboSet("REPORTPARAM",cronparamset.getUserInfo())
if reportparamset is not None:
print "working with REPORTPARAM
mbo set"

reportparamset.setWhere(sqf.format())
reportparamset.reset()
i=reportparamset.count()
reportparammbo = None
for j in range(i):
reportparam =
reportparamset.getMbo(j)
cronparam =
cronparamset.add(MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if cronparam is not None:
print "going to
copy values from REPORTPARAM into CRONTASKPARAM"

cronparam.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)

cronparam.setValue("INSTANCENAME",crontaskinstname,MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)

cronparam.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)
paramname =
reportparam.getString("PARAMNAME")

cronparam.setValue("PARAMETER",paramname,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if
paramname=="where":
#
prepare dynamic where clause for report params

uniqueidname = mbo.getUniqueIDName()

uniqueidvalue = mbo.getUniqueIDValue()

uniquewhere = uniqueidname + "=" + str(uniqueidvalue)

cronparam.setValue("VALUE",uniquewhere,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="paramstring":
print
'If condition for v_paramstring'

cronparam.setValue("VALUE",v_paramstring,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="paramdelimiter":
print
'If condition for v_paramdelimeter'

cronparam.setValue("VALUE",v_paramdelimeter,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="appname":

cronparam.setValue("VALUE",v_appname,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
else:
continue
reportschedset.save()

</script>

Many Thanks,


From: Incomm Solutions (2016-06-08 06:58)

An alternate idea is: if you can get the report saved as an attached document, you could set up a Communications Template to send it out...

Shannon ‎
Sent from my wonderful BlackBerry Z30 smartphone!
  Original Message  
From: 'Ian Turner' ian.turner@salisburycamra.org.uk [MAXIMO]
Sent: Wednesday, June 8, 2016 6:02 AM
To: MAXIMO@yahoogroups.com
Reply To: MAXIMO@yahoogroups.com
Subject: [MAXIMO List] Run Report Within Automation Script
Can anyone tell us how to attach a Birt report to an email within an
automation script? We are able to produce the blank template but there is no
content:
<script>
from java.util import Calendar
from java.util import Date
from psdi.app.report import ReportUtil
from psdi.server import MXServer
from psdi.mbo import MboConstants
from psdi.mbo import SqlFormat
from com.ibm.tivoli.maximo.report.birt.admin import ReportAdminServiceRemote
from com.ibm.tivoli.maximo.report.birt.runtime import
ReportExecutionParameterData
if str (v_reportname) is None:
print "Report name not supplied to script, exiting"
sys.exit(0)
print "WORKORDER status old value: " + str(v_status_initial)
print "WORKORDER status new value: " + str(v_status)
if (str(v_status) != str(v_status_initial)) and v_status=='APPR':
print "Status change is happening from " + str(v_status_initial) + "
to " + str (v_status)
# set a schedule for the report
c = Calendar.getInstance()
# add 60 seconds to current time to allow preparing REPORTSCHED cron
task instance
c.add(Calendar.SECOND,30)
d = c.getTime()
thisposet = mbo.getThisMboSet()
if thisposet is not None:
locale = thisposet.getClientLocale()
userinfo = thisposet.getUserInfo()
schedule =
ReportUtil.convertOnceToSchedule(d,locale,c.getTimeZone())
print "Schedule we have to set into REPORTSCHED Cron task is: " +
str(schedule)
if schedule is not None:
reportschedset =
MXServer.getMXServer().getMboSet("REPORTSCHED",userinfo)
if reportschedset is not None:
print "Obtained REPORTSCHED set"
reportsched = reportschedset.add()
reportsched.setValue("REPORTNAME",v_reportname)
reportsched.setValue ("appname",v_appname)
reportsched.setValue
("USERID",userinfo.getUserName())
reportsched.setValue ("TYPE","once")
reportsched.setValue("EMAILTYPE",v_emailtype)
reportsched.setValue("MAXIMOURL",v_maximourl)
reportsched.setValue("EMAILUSERS",v_emailto)
reportsched.setValue("EMAILSUBJECT",v_emailsubject)
reportsched.setValue("EMAILCOMMENTS",v_emailcomments)
reportsched.setValue("EMAILFILETYPE",v_emailfiletype)
reportsched.setValue("COUNTRY",locale.getCountry())
reportsched.setValue("LANGUAGE",locale.getLanguage())
reportsched.setValue("VARIANT",locale.getVariant())
reportsched.setValue("TIMEZONE",thisposet.getClientTimeZone().getID())
reportsched.setValue("LANGCODE",userinfo.getLangCode())
woSet =
MXServer.getMXServer().getMboSet("WORKORDER",userinfo)
print "About to work with REPORTSCHEDULE cron task"
crontaskdef =
reportsched.getMboSet("$parent","crontaskdef","crontaskname='REPORTSCHEDULE'
").getMbo(0)
if crontaskdef is not None:
crontaskinstset =
crontaskdef.getMboSet("CRONTASKINSTANCE")
if crontaskinstset is not None:
print "About to work with Cron task
instance of REPORTSCHEDULE cron task"
crontaskinst =
crontaskinstset.add(MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if crontaskinst is not None:
d = Date()
crontaskinstname =
str(d.getTime())
crontaskinst.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSC
HECK | MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("INSTANCENAME",crontaskinstname,MboConstants.NOACCESSC
HECK | MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("SCHEDULE",schedule,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("ACTIVE",1,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("RUNASUSERID",userinfo.getUserName(),MboConstants.NOAC
CESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("HASLD",0,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
crontaskinst.setValue("AUTOREMOVAL",True,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
print "have set all cron
task instance values for REPORTSCHEDULE cron task"
reportsched.setValue("CRONTASKNAME",crontaskinst.getString("CRONTASKNAME"))
reportsched.setValue("INSTANCENAME",crontaskinst.getString("INSTANCENAME"))
print "Now going to work with Cron task PARAMETERS"
cronparamset = crontaskinst.getMboSet("PARAMETER")
if cronparamset is not None:
sqf =
SqlFormat(cronparamset.getUserInfo(),"reportname=:1")
sqf.setObject(1,"REPORTPARAM","REPORTNAME",v_reportname)
reportparamset =
MXServer.getMXServer().getMboSet("REPORTPARAM",cronparamset.getUserInfo())
if reportparamset is not None:
print "working with REPORTPARAM
mbo set"
reportparamset.setWhere(sqf.format())
reportparamset.reset()
i=reportparamset.count()
reportparammbo = None
for j in range(i):
reportparam =
reportparamset.getMbo(j)
cronparam =
cronparamset.add(MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if cronparam is not None:
print "going to
copy values from REPORTPARAM into CRONTASKPARAM"
cronparam.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)
cronparam.setValue("INSTANCENAME",crontaskinstname,MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)
cronparam.setValue("CRONTASKNAME","REPORTSCHEDULE",MboConstants.NOACCESSCHEC
K | MboConstants.NOVALIDATION_AND_NOACTION)
paramname =
reportparam.getString("PARAMNAME")
cronparam.setValue("PARAMETER",paramname,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
if
paramname=="where":
#
prepare dynamic where clause for report params
uniqueidname = mbo.getUniqueIDName()
uniqueidvalue = mbo.getUniqueIDValue()
uniquewhere = uniqueidname + "=" + str(uniqueidvalue)
cronparam.setValue("VALUE",uniquewhere,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="paramstring":
print
'If condition for v_paramstring'
cronparam.setValue("VALUE",v_paramstring,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="paramdelimiter":
print
'If condition for v_paramdelimeter'
cronparam.setValue("VALUE",v_paramdelimeter,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
elif
paramname=="appname":
cronparam.setValue("VALUE",v_appname,MboConstants.NOACCESSCHECK |
MboConstants.NOVALIDATION_AND_NOACTION)
else:
continue
reportschedset.save()
</script>
Many Thanks,