Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3314930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:17:26+00:00 2026-05-17T22:17:26+00:00

I am working with an IBM Maximo database that issues workorders automatically. When the

  • 0

I am working with an IBM Maximo database that issues workorders automatically. When the workorders are issued (aka Inserted into the database workorder table), I would like to auto-assign a supervisor, owner, and owner group based on a set of criteria. This only needs to happen IF the supervisor, owner, and owner group aren’t already assigned. Often times a “parent workorder” has the information, but it needs to be copied into the “child” workorders (as you will see in the criteria below). The criteria for ALL of the triggers is:

WHERE status<>'COMP'
AND historyflag=0
AND istask=0

Here is the criteria for the trigger:

-If the Owner Group and Supervisor have a value, skip the record. (Do nothing)

-If the Owner Group and/or Supervisor is blank or null, and the corresponding PARENT Work
Order field is not Null, copy the Owner Group and/or Supervisor from the
PARENT Work Order record.

-If the Parent Work Order Owner Group and/or Supervisor is blank or null, then
assign the Owner Group and Supervisor per the table values below: (I have removed names for security’s sake, but all the columns are correct, i.e. B3 is supposed to have SuperA as the supervisor)

Site / OwnerGroup / Supervisor
ABC / @ABCGroup / @ABCSupervisor
DEF / @DEFGroup / @DEFSupervisor

**NOTE:
SITE is not a table column, it is really the first 3 characters of the workorder.location field. For example, the location could be ABC-1234, meaning it is at site ABC, building 1234 (unfortunately, these are NOT stored in separate columns, they are only present together in the location column). In this SQL query, all buildings at a location are serviced by the same ownergroup/supervisor, so all other queries we currently use are using workorder.location=’ABC%’

I’ve done plenty of selects, updates, and stored procedures, but this is my first trigger and want to make sure I don’t royally screw up the database! Any and all help is greatly appreciated!

For those unfamiliar with Maximo, the table is:
dbo.workorder
and the fields are:
location,ownergroup,supervisor


UPDATE1:
Here is some additional information that may be of importance.
Locations:
First off, workorder.location will contain values such as ABC-1234, meaning it is at site ABC, building 1234 (though these are NOT separate values, it’s combined). In this SQL query, all buildings at a location are serviced by the same ownergroup/supervisor, so all queries use something similar to workorder.location=’ABC%’.

Here is what I would like the logic to look like for the final query:


If the supervisor field is missing, first look to see if it has a parent, and if so, does the parent have a supervisor? If not, assign based on the table above.

If the ownergroup field is missing, first look to see if it has a parent, and if so, does the parent have an ownergroup? If not, assign based on the table above.

This is why I am thinking a case statement maybe the best option. Also, I currently have a list of variables such as “@ASupervisor, @B1Supervisor, @B2Supervisor,…etc” so that I can change them in the future if need be. To save a lot of redundant code, is it possible to do something like:
(in this example, location is ABC-1234, ownergroup SHOULD be @ABCGroup, supervisor should be @ABCSupervisor, where @ABCGroup and @ABCSupervisor are set earlier in the code)

If the supervisor field is missing, first look to see if it has a parent, and if so, does the parent have a supervisor (then copy it’s supervisor)? If not, assign supervisor X.
Where X = ‘@’ + ‘(the first three characters of the location)’ + ‘Supervisor’ (in this example, X=@ABCSupervisor)

Is this possible??


UPDATE 2:

I have spoken with the person who asked for this database change and we have changed some thinking here. First, parent locations and child locations should always be the same (if they’re not, that’s a WHOLE OTHER issue). All sites (first 3 letters of location) should have the same ownergroup and supervisor, so essentially we can just look to see if a workorder entry has a NULL value in either field, then assign it based on the location. I believe the following code will work (but would like someone to review it before I implement it on the system)

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER dbo.AutoAssign
   ON  dbo.workorder
   AFTER INSERT,UPDATE
AS 
BEGIN
    SET NOCOUNT ON;

    DECLARE @ABCSupervisor varchar(30)
    DECLARE @DEFSupervisor varchar(30)

    DECLARE @ABCOwnerGroup varchar(20)
    DECLARE @DEFOwnerGroup varchar(20)


    /*EDIT VARIABLES IF FUTURE CHANGES*/
    --SET Supervisor values HERE;
    SET @ABCSupervisor='JOHNDOE' 
    SET @XYZSupervisor='JANEDOE' 

    --SET OwnerGroup values HERE:
    SET @ABCOwnerGroup='ALPHATEAM' 
    SET @XYZOwnerGroup='OMEGATEAM' 

    --UPDATES
    UPDATE dbo.workorder
        SET ownergroup='@'+SUBSTR(location,1,3)+'OwnerGroup'
    WHERE status<>'COMP'
        AND historyflag=0
        AND istask=0    
        AND ownergroup IS NULL
        AND location IS NOT NULL

    UPDATE dbo.workorder
        SET supervisor='@'+SUBSTR(location,1,3)+'Supervisor'
    WHERE status<>'COMP'
        AND historyflag=0
        AND istask=0
        AND supervisor IS NULL
        AND location IS NOT NULL
END
GO

The only issues I see here are that I do not join of some sort on the “inserted” table so that it only affects those entries (and not the entire table every time). If I could get some help on that, it would be greatly appreciated!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:17:27+00:00Added an answer on May 17, 2026 at 10:17 pm

    if you have done some update-statements you are on the right way.
    put the virtual table INSERTED in your update-statement and join it with a unique-key, e.g. SerialNo: that would be something like that:

    create trigger Trig_WorkOrder for insert, update as
    BEGIN
    update wo
    set location = pwo.location, ...
    from dbo.workorder as wo, inserted as i, dbo.parentworkorder as pwo
    where wo.serialNo = i.SerialNo -- join with the actual table-entry
    and wo.pwo_id = pwo.id -- join with the parentworkorder
    and i.ownergroup is null -- do it if new value is empty
    and (pwo.ownergroup is not null or pwo.ownergroup <> '') -- do it if parentvalue is not empty
    and (pwo.Supervisor is not null or pwo.Supervisor <> '') -- do it if parentvalue is not empty
    
    update wo
    set location = pwo.location, ...
    from dbo.workorder as wo, inserted as i, dbo.standardworkorder as pwo
    where wo.serialNo = i.SerialNo 
    and wo.location = pwo.location
    and wo.ownergroup is null
    and (pwo.ownergroup is null or pwo.ownergroup = '')
    and (pwo.Supervisor is null or pwo.Supervisor = '')
    END
    

    I would sugest to store the default values in a separate table, for convenient joining if the parentvalues are empty.

    Put two update-statements inside the trigger an code the where-clause to make sure that only one statement executes…

    peace and good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project that parses a log of events, and then updates a
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
I have a script that appends some rows to a table. One of the
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch
Working on a project at the moment and we have to implement soft deletion
Working on a somewhat complex page for configuring customers at work. The setup is
Working with python interactively, it's sometimes necessary to display a result which is some
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working with TCL and I'd like to implement something like the Strategy Pattern .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.