Showing posts with label reuseable script. Show all posts
Showing posts with label reuseable script. Show all posts

Tuesday, 19 January 2021

Reuseable Scripts - Invoke a Script from a Script - Jython | Maximo

 Question:

  1. Can we invoke a script from another script?
  2. Is it possible to reuse the existing Script?
  3. Can we make the Global function and call it in the script when required?

Solution:

My answer is yes to all the above questions, let's start with this example. 

--- " Do this job within 5 business days (excluding weekends (Friday, Saturday))! "

Okay. Today is 19-Jan, what is my, etc after 5 days.


we will handle this with 2 scripts: 

  1. a library script to take the parameter of date + days and gives an output. 
  2. our script from where we will call the library script. 
1. Create a Library Script and name it any like "LS-GETNEXTBUSINESSDAY"
copy the paste the code below into the body of it. 

from java.util import Calendar
cal = Calendar.getInstance();
cal.setTime(d)
loop=1
while(loop<=n) :
    cal.add(cal.DATE, +1)
    if (cal.get(cal.DAY_OF_WEEK)) not in [cal.FRIDAY,cal.SATURDAY] : 
        loop=loop+1
vNextBDay = cal.getTime()

2.  Call this function from another script with 2 parameters d, n ( date, days)