Question:
- Can we invoke a script from another script?
- Is it possible to reuse the existing Script?
- 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:
- a library script to take the parameter of date + days and gives an output.
- 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 Calendarcal = Calendar.getInstance();cal.setTime(d)loop=1while(loop<=n) :cal.add(cal.DATE, +1)if (cal.get(cal.DAY_OF_WEEK)) not in [cal.FRIDAY,cal.SATURDAY] :loop=loop+1vNextBDay = cal.getTime()
2. Call this function from another script with 2 parameters d, n ( date, days)