MaxTECH Maximo Technical User Group

 View Only
  • 1.  Set Workorder Actual Start/Finish to First and Last Labtrans Entry

    Posted Wed September 12, 2018 02:10 PM
    Currently we use a DB Trigger (SQL) to set the Work Order Actual Start & Finish Date/Time to the First and Last Labtrans Entry for a WO. 

    Purpose is to identify the real actual start and actual finish of work on the WO.

    Example:
    WO#123456   Labor 9/10/18 9:00am - This would be the ACTSTART
    WO#123456   Labor 9/11/18 2:00pm
    WO#123456   Labor 9/12/18 7:00am - This would be the ACTFINISH

    I want to move this into an Automation Script.
    Any suggestions on the scripting to use?

    ------------------------------
    Duane (Woodie) Wood
    CMMS Manager
    EMCOR Government Services| Inc.
    Arlington VA
    571-403-8940
    ------------------------------


  • 2.  RE: Set Workorder Actual Start/Finish to First and Last Labtrans Entry

    Posted Thu September 13, 2018 08:29 AM

    Are your labor transactions approved manually or automatically? If they are automatically approved (the
    GENAPPRSERVRECEIPT attribute is set to 1 on creation) then you would probably want to do this with an Object Launch point on LABTRANS. You would choose an event of Save, and on the save events you should be able to just check Add (and leave it with the default of Before Save for when it fires). 

    If you're approving labor, since the dates can be modified after it's created you would want to set it with an Attribute launch point on GENAPPRSERVRECEIPT with a Run action event so that you only fire when it's being approved. Run action is preferred over validate because you want to ensure the data is valid before performing an action. 

    Beyond that, you should be able to utilize your existing trigger for a lot of reference on how you're calculating and what you're updating. For example:
    1) Should it roll up to the parent WO if it's a task
    2) what dates are you comparing (startdatetime/finishdatetime is great if each labor entry has a date and a time because it will combine the Start Date & Start Time fields, otherwise you'll need to check for this being null and then compare the actual start date field).

    From there, the only other thing that becomes a bit more complicated is you need to think of how to do it in a way that Maximo would. For example, if you're in Work Order Tracking and adding your labor you'll want to use the owner record (wo=mbo.getOwner()) because that will enable you to set the Work Order record that exists in memory. This avoids potentially causing a record updated by another user error. If the labor is entered using Labor Reporting though, there is no owner so you'd want to use the same relationship as IBM does to update the Work Order actuals so you'd again avoid the updated by another user error. In that case, you're code would look like this:

    wo=mbo.getMboSet("WORKORDER").getMbo(0)



    ------------------------------
    Steven Shull
    Solution Architect/Development Lead
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 3.  RE: Set Workorder Actual Start/Finish to First and Last Labtrans Entry

    Posted Thu September 13, 2018 10:57 AM
    Steven Shull has already given a very good answer. But if you're trying to decide which automation scripting language to choose, I recommend going with Jython / Python (no material difference.. they're both Python running on a JVM) over going with JavaScript for a number of reasons, but here are the 3 main reasons:
    1. When IBM's examples / Technotes / etc aren't given in both Jython and JavaScript, they tend to be in Jython. So, IBM apparently prefers Jython.
    2. JavaScript's "delete" keyword conflicts with the "delete()" method on many Maximo classes.
    3. Jython's syntax is cleaner. It has less mandatory clutter than JavaScript.


    ------------------------------
    Blessings,
    Jason Uppenborn
    Maximo Consultant
    Ontracks Consulting
    ------------------------------



  • 4.  RE: Set Workorder Actual Start/Finish to First and Last Labtrans Entry

    Posted Fri September 14, 2018 07:23 AM

    So we do both Auto-Approved in some Organizations and Manual in others.

    We do use WOTRACK and LABREP.

    I would probably do the Attribute Launch Point on GENAPPRSERVRECEIPT as you suggested. This way it would not update until labor was approved and locked into place.

    We don't use Parent/Child or Labor on Tasks so these are out of the mix.

    In the trigger, we do combine the date/time fields then pull the Min/Max values (see below)

    I'm pretty decent with SQL, but not so good with Java.

    It's the script part that I'm looking for. 

     

    Here's our current trigger (it's not perfect, but worked for the last decade):

    FOR INSERT, UPDATE AS 

      /* SET NOCOUNT ON added to prevent extra result sets from interfering with SELECT statements.*/

     

      SET NOCOUNT ON 

      DECLARE @v_refwo VARCHAR(10),                      

      @v_siteid VARCHAR(8),                             

      @v_startdate DATETIME,                          

      @v_starttime DATETIME,                          

      @v_finishdate DATETIME,                        

      @v_finishtime DATETIME,                        

      @v_inserted_start DATETIME,                               

      @v_inserted_finish DATETIME,                              

      @v_actstart DATETIME,                             

      @v_actfinish DATETIME,                           

      @v_first_labtrans_start DATETIME,                     

      @v_last_labtrans_finish DATETIME,                     

      @v_new_start DATETIME,                       

      @v_new_finish DATETIME,

      @v_approveby VARCHAR(30)  

     

    /*Get the relevant inserted values*/ 

      SELECT                               

      @v_refwo = REFWO,                  

      @v_siteid = SITEID,                      

      @v_startdate = STARTDATE,    

      @v_starttime = STARTTIME,                    

      @v_finishdate = FINISHDATE,

      @v_finishtime = FINISHTIME                   

                                   

      FROM INSERTED where  @v_approveby is not null  

    /* Set the inserted start and finish variables*/

                                   

      SET       @v_inserted_start = @v_startdate + @v_starttime

      SET       @v_inserted_finish = @v_finishdate + @v_finishtime 

                                      

    /*  Get the earliest start and latest finish times from existing labtrans records.*/

                                       

      SELECT @v_first_labtrans_start = MIN(Convert(datetime, Convert(char(10), DBO.v_LABTRANS.STARTDATE, 103) + ' ' + Convert(char(8), DBO.v_LABTRANS.STARTTIME, 108), 103) ),

                                     @v_last_labtrans_finish = MAX(Convert(datetime, Convert(char(10), DBO.v_LABTRANS.FINISHDATE, 103) + ' ' + Convert(char(8), DBO.v_LABTRANS.finishtime, 108), 103) )                    

      FROM DBO.v_LABTRANS                           

      WHERE v_LABTRANS.siteid=@v_siteid and                       

            v_LABTRANS.REFWO = @v_refwo                  

       GROUP BY v_LABTRANS.REFWO

                                      

    /* Set the new start date.  Check if the inserted start date is earlier that the earliest existing labtrans record.*/

       IF @v_first_labtrans_start IS NULL OR  @v_inserted_start < @v_first_labtrans_start                  

       SET @v_new_start =  @v_inserted_start ELSE                                

       SET @v_new_start =  @v_first_labtrans_start  

     

    /* Set the new finish date.  Check if the inserted finish date is later that the latest existing labtrans record.*/

       IF @v_last_labtrans_finish IS NULL OR  @v_inserted_finish > @v_last_labtrans_finish                               

       SET @v_new_finish =  @v_inserted_start ELSE                              

       SET @v_new_finish =  @v_last_labtrans_finish             

                                        

                                      

                                        UPDATE dbo.workorder

                                        SET actstart = dateadd(hh,-3,@v_new_start),               

                                        actfinish  = dateadd(hh,-3,@v_new_finish)                    

                                        from dbo.workorder                 

                                        WHERE workorder.siteid = @v_siteid and workorder.wonum = @v_refwo



    ------------------------------
    Duane (Woodie) Wood
    CMMS Manager
    EMCOR Government Services| Inc.
    Arlington VA
    571-403-8940
    ------------------------------