Writing a file to server path through an automation script & cron #Maximo #cron #automationscript #Maximofilewriter
Scenario : As part of integration we need to write a file at a regular interval to a server path.
Steps to achieve :
1. Create a path in server under MIF folder.
2. Create a script to create a file.
3. Associate the created script as a parameter to the cron.
Lets do this!
1. Create a folder under F drive in the server box:
F:\MIF\INTEGRATION_EX\OUTBOUND
The file that we are about to write will fall under the folder INTEGRATION\OUTBOUND that we have created under F drive, MIF folder.
2. Create a script:
Go To Automation script and Click on Create Script > Script. This being a cron script it would not need a launchpoint.
Script = XXXINTEGRATION
Description = To write an Integration file
Script Language = Jython
----Sample code like below----
#Library
import psdi.server.MXServer
import java.io.BufferedWriter
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.util.Date
from datetime import datetime, date
#Defining Path & file name details
date=str(date.today())
DATED='INTEGRATIONFILE'+date
#Path definition where the file has to be created
PATH="F:\MIF\INTEGRATION_EX\OUTBOUND\EXAMPLE_"+DATED+".txt"
bfWritter=BufferedWriter(FileWriter(PATH))
#Getting work order details
woSet = MXServer.getMXServer().getMboSet("WORKORDER", MXServer.getMXServer().getSystemUserInfo());
woSet.setWhere(" status='APPR' and finStatus='APPR' ")
woSet.reset()
woList=[]
if (woSet is not None and not woSet.isEmpty()):
for i in range(0,woSet.count()):
wonum=woSet.getMbo(i).getString("WONUM")
if wonum not in woList:
woList.append(wonum)
status=woSet.getMbo(i).getString("STATUS")
appDate=woSet.getMbo(i).getDate("APPRDATE")
glAccount=woSet.getMbo(i).getString("GLACCOUNT")
#Writing the file from here
bfWritter.write('AA')
bfWritter.write(wonum)
bfWritter.write(status)
bfWritter.write(appDate)
bfWritter.write('0000')
bfWritter.write(glAccount)
bfWritter.write('11AA00')
for value in woList:
woSet = MXServer.getMXServer().getMboSet("WORKORDER", MXServer.getMXServer().getSystemUserInfo())
woSet.setWhere(" wonum= '"+value+"' and status='APPR' ")
woSet.reset()
woCount=woSet.count()
#Statistic record
bfWritter.write("STATISTICS OF ")
bfWritter.write(wonum)
bfWritter.write(" ")
bfWritter.write("TOTAL RECORDS ")
bfWritter.write(woCount)
bfWritter.close()
3. Script association to cron:
Go To --> System Configuration --> Platform Configuration -->Cron Task Setup
Click on New Cron Task Setup
Cron Task = XXX_INTEGRATION
Description = Cron for writing a Integration file
Class = com.ibm.tivoli.maximo.script.ScriptCrontask
Access Level = FULL
Cron Task Instance Name = INTEGFILECRONTASK
Description = Task for Cron
Schedule = 1d,0,30,12,*,*,*,*,*,*
Run as User = MAXADMIN
Active = 1
Keep History = 1
Max Number of History Records = 10000
#Parameters, SCRIPTARG = None, SCRIPTNAME = Script Name
SCRIPTARG = None
SCRIPTNAME = XXXINTEGRATION
********************************************************************************************************
Comments
Post a Comment