Hi Trisha,
See below query and update statements that I use to reverts the status of a work order back. The comments in [ ] are what the queries return or what to expect
use [your Maximo Environment];
DECLARE @wonum as nvarchar(30);
SET @wonum='[WONUM]'
SELECT 'workorder', wonum, parent, status, statusdate, firstapprstatus, *
FROM workorder WHERE wonum=@wonum OR parent=@wonum order by 1;
SELECT 'wostatus SELECT to DELETE',* FROM wostatus
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum AND status<>'CLOSE')
AND status in ('[Statuses after the status you want to go back to]')
ORDER BY wonum, changedate DESC;
--[NOTE: Run the above first to ensure that you capture the statuses you want to remove from WOSTATUS]
--DELETE FROM wostatus
--WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum)
--AND status in ('[Statuses after the status you want to go back to from above]');
SELECT 'wostatus SELECT after DELETE ',* FROM wostatus
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum AND status <> 'CLOSE')
ORDER BY wonum, changedate DESC;
SELECT 'workorder', wonum, parent, status, statusdate, firstapprstatus, * FROM workorder
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum AND status <> 'CLOSE')
ORDER BY 2;
--[NOTE: Run the above second to ensure that the statuses you want to remove from WOSTATUS have been deleted]
--update workorder
--SET status ='APPR' --[only needed if status is an unapproved status] ,firstapprstatus=NULL --[status you want to revert back to]
--, historyflag ='0' --[required if historyflag =1]
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum AND status <> 'CLOSE');
--[Checks to see that the correct changes have been made]
SELECT 'workorder after UPDATE', wonum, parent, status, parentchgsstatus, statusdate, firstapprstatus, * FROM workorder
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum AND status <> 'CLOSE')
ORDER BY 2;
SELECT * FROM wostatus
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum);
SELECT historyflag, firstapprstatus, * FROM WORKORDER
WHERE wonum IN (SELECT wonum FROM workorder WHERE wonum=@wonum OR parent=@wonum);
Hope this is of some help.
Cheers
JB
------------------------------
John Bauer
Mercury
------------------------------
Original Message:
Sent: 03-25-2024 06:21
From: Trisha S
Subject: Update workorder status to its previous status
Hi All,
I have some workorders which have been completed recently by someone mistakenly and now I have to revert that change and update the status of those workorders back as those were before completion happened.
As my understanding,i believe if i update workorder and woactivity tables with:
Update workorder set status='Appr', status date= (hardcode the date value)where....
And delete that row from wos status table.
Is there anything thing else that i am missing?
Or any other method apart from sql to make this change?
Thanks.
#EverythingMaximo
------------------------------
Trisha S
Tcs
------------------------------