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.
I am atempting to calculate the difference between two newly added attributes that are configured as date (not datetime).
Attributes:
lr_schedfinish lr_actfinish lr_slippage
I have reviewed the following article:
Maximo Technical and Functional Concepts: Automation Script - get difference between dates http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html
Maximo Technical and Functional Concepts: Automation Script - get difference between dates http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html If you want to get a difference between two dates in Maximo automation scripts, I tried below process: For example:
View on maximotechnofunctional.blogspot.nl http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html
Preview by Yahoo
And modified the script accordingly (see below) and am running the script as jython, with the following variables:
Variables:
lr_schedfinish = schedfinish
lr_actfinish= actfiniah
lr_slippage = slippage
#************** AUTO SCRIPT START ***************
#Define a function to get date difference
#************** FUNCTION START ***************
def getDateDiff(timeDiff):
milliseconds = 1000
milliminutes = milliseconds * 60
millihours = milliminutes * 60
millidays = millihours * 24
daysDiff = timeDiff / millidays
hoursDiff = timeDiff/millihours
minDiff = timeDiff / milliminutes
if(daysDiff != 0):
return int(daysDiff)
#************** FUNCTION END ***************
timeDiff = actfinish.getTime() - schedfinish.getTime()
daysDiffernce = getDateDiff(timeDiff)
slippage = daysDifference
#************** AUTO SCRIPT END ***************
When compiling I get the following error:
The script did not compile.
SyntaxError: 'return' outside function in <script> at line number 16 at column number 1
I am wondering if anyone can help with the error above or if there is a better/easier way to do this?
Thanks,
Mike
Shouldn't all the lines that make up the function body be indented with spaces? Jython/Python uses indentation to define the structure. Add a couple of spaces to every line in the function up to and including the return (but not the def)
On January 11, 2016 at 1:38:34 PM GMT, mlevinson@ledgesoft.com [MAXIMO] <MAXIMO@yahoogroups.com> wrote: I am atempting to calculate the difference between two newly added attributes that are configured as date (not datetime). Attributes: lr_schedfinish lr_actfinish lr_slippage I have reviewed the following article: Maximo Technical and Functional Concepts: Automation Script - get difference between dates http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html Maximo Technical and Functional Concepts: Automation Script - get difference between dates http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html If you want to get a difference between two dates in Maximo automation scripts, I tried below process: For example: View on maximotechnofunctional.blogspot.nl http://maximotechnofunctional.blogspot.nl/2015/05/automation-script-get-difference.html Preview by Yahoo And modified the script accordingly (see below) and am running the script as jython, with the following variables: Variables: lr_schedfinish = schedfinish lr_actfinish= actfiniah lr_slippage = slippage #************** AUTO SCRIPT START *************** #Define a function to get date difference #************** FUNCTION START *************** def getDateDiff(timeDiff): milliseconds = 1000 milliminutes = milliseconds * 60 millihours = milliminutes * 60 millidays = millihours * 24 daysDiff = timeDiff / millidays hoursDiff = timeDiff/millihours minDiff = timeDiff / milliminutes if(daysDiff != 0): return int(daysDiff) #************** FUNCTION END *************** timeDiff = actfinish.getTime() - schedfinish.getTime() daysDiffernce = getDateDiff(timeDiff) slippage = daysDifference #************** AUTO SCRIPT END *************** When compiling I get the following error: The script did not compile. SyntaxError: 'return' outside function in <script> at line number 16 at column number 1 I am wondering if anyone can help with the error above or if there is a better/easier way to do this? Thanks, Mike
Thanks for the response Chris. The indent did the trick for letting me compile.
When I update the launching attribute (LR_ACTFINISH) I get the following error:
An error occured that prevented the PSECALCSLIPPAGE script for the PSECALCSLIPPAGE launch point from running.
TypeError: unsupported operand type(s) for /: 'java.math.BigInteger' and 'int' in <script> at line number 21
I have the following attributes configured as follows:
LR_SCHEDFINISH (DATE)
LR_ACTFINISH (DATE)
LR_SLIPPAGE (INTEGER)
My suggestion? Make sure your code is largely functional with some stubs before moving to Maximo. Try: Python Cloud IDE | Python Fiddle http://pythonfiddle.com/
Python Cloud IDE | Python Fiddle http://pythonfiddle.com/ The Python IDE for the web. Play around with and modify live example code. Share or demonstrate solutions to problems.
View on pythonfiddle.com http://pythonfiddle.com/
Preview by Yahoo
If it works there, using some test constants for dates and integers, then at least you'll know your problem is working within Maximo and not the language itself.
---In MAXIMO@yahoogroups.com, <mlevinson@ledgesoft.com> wrote :
Thanks for the response Chris. The indent did the trick for letting me compile.
When I update the launching attribute (LR_ACTFINISH) I get the following error:
An error occured that prevented the PSECALCSLIPPAGE script for the PSECALCSLIPPAGE launch point from running.
TypeError: unsupported operand type(s) for /: 'java.math.BigInteger' and 'int' in <script> at line number 21
I have the following attributes configured as follows:
LR_SCHEDFINISH (DATE)
LR_ACTFINISH (DATE)
LR_SLIPPAGE (INTEGER)