Maximo Open Forum

 View Only
  • 1.  Compare dates in automation script

    Posted 06-06-2023 09:22

    Hi,

    I have this below query,

    ) currentset=mxserver.getMboSet("taskschedular",userInfo)

    currentset.setWhere(" taskname like '%pmwogen%) currentMbo= currentSet.getMbo(0)

    datepmwogen = currentMbo.getDate("lastrun")

    Now if datepmwogen value is 2022-12-05 , how do i extract the month,year,date and compare with todays date month year and date , in a script?


    #Administration
    #Analytics
    #Architecture
    #Assets
    #CivilInfrastructure
    #Customizations
    #EndUser
    #EverythingMaximo
    #HSE/OilandGas
    #Infrastructure
    #Integrations
    #Inventory
    #IoT
    #LifeScience/Calibration
    #Linear
    #MaximoApplicationSuite
    #MaximoForAviation
    #MaximoUserGroups
    #Mobility
    #Nuclear
    #Procurement
    #Reporting
    #Scheduling
    #Security
    #ServiceProvider
    #Spatial
    #Transportation
    #Utilities
    #WorkCenters
    #WorkManagement

    ------------------------------
    Deepa P
    ------------------------------


  • 2.  RE: Compare dates in automation script

    Posted 06-07-2023 10:26
    var datepmwogen = "2022-12-05";
    var dateObj = new Date(datepmwogen);
    var month = dateObj.getMonth() + 1; 
    var year = dateObj.getFullYear();
    var day = dateObj.getDate();
    var today = new Date();
    var currentMonth = today.getMonth() + 1;
    var currentYear = today.getFullYear();
    var currentDay = today.getDate();
    if (year === currentYear && month === currentMonth && day === currentDay) {
      ...
    }



    ------------------------------
    Prashant Sharma
    Sedin Technologies
    Connect with me @ https://www.linkedin.com/in/psharmamaximo/

    #IBM Champion 2022
    #IBM Champion 2023
    ------------------------------



  • 3.  RE: Compare dates in automation script

    Posted 06-07-2023 11:16

    While autoscripting, bear in mind that even though the syntax of your script may be Python or JavaScript, your script is executing in the Java Virtual Machine that is running Maximo. That means you have at your fingertips all of the native Java libraries as well as all the third-party libraries that Maximo comes with.

    To get date parts out of a java.util.Date, which will be returned by your `currentMbo.getDate("lastrun")` call, you need to use that Date to create a Calendar, e.g. java.util.GregorianCalendar, that is set to your Date, and then pull the date parts out of the Calendar.

    You can find documentation on the native Java libraries here: GregorianCalendar (Java Platform SE 8 ) (oracle.com)



    ------------------------------
    Jason Uppenborn
    Cohesive
    ------------------------------