Home > Forum > General > [SOLVED] How to build table with history - who finished the step

[SOLVED] How to build table with history - who finished the step
0

I try to build table with short history to put it in protocol (word>>pdf) of acceptance
So i would like to have 3 columns:

1) person
2) behalf (if was)
3) time step


at the moment I'm struggle with filtration .... skip save or other than end step paths ...

in green lat 2 - the "steps" where I clicked - finish ..live the step ...
where I have 1 person and no waiting for other to finish - it was easy ..
but if in step I have assigned 2-3 people and one of then is behalf
then ... is more difficult ...


SQL query:

[code="SQL"]
SELECT
WFH_ID as 'ID of history',
WFH_STPID as 'Krok ID',
WFH_FinishDurationDateTime AS 'Data ukończenia kroku',
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
dbo.clearwfelem(WFH_LeftBy) AS 'Zatwierdzone przez',
dbo.clearwfelem(WFH_LeftByImpersonator) AS 'W Zastępstwie',
FORMAT(
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END, 'dd.MM.yyyy HH:mm:ss'
) AS 'Data akceptacji'
FROM
WFHistoryElements
WHERE
WFH_OrgID = {WFD_ID}
AND WFH_STPID = {ST:369}
and WFH_IsLastVersionInCurrentStep<>''
-- AND WFH_LeftByImpersonator <> ''

[/code]

P.S.
webcon 2024.1.161

Chat GPT generated 2 codes:

1. for Data Table
[code]
WITH RankedHistory AS (
SELECT
WFH_ID AS ID_of_history,
WFH_TransitionReason,
WFH_STPID AS Krok_ID,
WFH_FinishDurationDateTime AS Data_ukończenia_kroku,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
dbo.clearwfelem(WFH_LeftBy) AS Zatwierdzone_przez,
dbo.clearwfelem(WFH_LeftByImpersonator) AS W_Zastępstwie,
FORMAT(
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END, 'dd.MM.yyyy HH:mm:ss'
) AS Data_akceptacji,
ROW_NUMBER() OVER (
PARTITION BY dbo.clearwfelem(WFH_LeftBy)
ORDER BY
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END DESC
) AS RowNum
FROM
WFHistoryElements
WHERE
WFH_OrgID = {WFD_ID}
AND WFH_STPID = {ST:369}
AND WFH_IsLastVersionInCurrentStep <> ''
)
SELECT
ID_of_history,
WFH_TransitionReason,
Krok_ID,
Data_ukończenia_kroku,
Zatwierdzone_przez,
W_Zastępstwie,
Data_akceptacji
FROM
RankedHistory
WHERE
RowNum = 1
ORDER BY
Data_akceptacji DESC;
[/code]

2 for action:
[code]
SELECT
WFH_ID AS ID_of_history,
WFH_TransitionReason,
WFH_STPID AS Krok_ID,
WFH_FinishDurationDateTime AS Data_ukończenia_kroku,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
dbo.clearwfelem(WFH_LeftBy) AS Zatwierdzone_przez,
dbo.clearwfelem(WFH_LeftByImpersonator) AS W_Zastępstwie,
FORMAT(
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END, 'dd.MM.yyyy HH:mm:ss'
) AS Data_akceptacji
FROM
(SELECT
WFH_ID,
WFH_TransitionReason,
WFH_STPID,
WFH_FinishDurationDateTime,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
WFH_LeftBy,
WFH_LeftByImpersonator,
ROW_NUMBER() OVER (
PARTITION BY dbo.clearwfelem(WFH_LeftBy)
ORDER BY
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END DESC
) AS RowNum
FROM WFHistoryElements
WHERE
WFH_OrgID = {WFD_ID}
AND WFH_STPID = {ST:369}
AND WFH_IsLastVersionInCurrentStep <> ''
) AS RankedHistory
WHERE
RowNum = 1
ORDER BY
Data_akceptacji DESC;
[/code]

MVP
In reply to: Paweł Tołoczko

Chat GPT generated 2 codes:

1. for Data Table
[code]
WITH RankedHistory AS (
SELECT
WFH_ID AS ID_of_history,
WFH_TransitionReason,
WFH_STPID AS Krok_ID,
WFH_FinishDurationDateTime AS Data_ukończenia_kroku,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
dbo.clearwfelem(WFH_LeftBy) AS Zatwierdzone_przez,
dbo.clearwfelem(WFH_LeftByImpersonator) AS W_Zastępstwie,
FORMAT(
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END, 'dd.MM.yyyy HH:mm:ss'
) AS Data_akceptacji,
ROW_NUMBER() OVER (
PARTITION BY dbo.clearwfelem(WFH_LeftBy)
ORDER BY
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END DESC
) AS RowNum
FROM
WFHistoryElements
WHERE
WFH_OrgID = {WFD_ID}
AND WFH_STPID = {ST:369}
AND WFH_IsLastVersionInCurrentStep <> ''
)
SELECT
ID_of_history,
WFH_TransitionReason,
Krok_ID,
Data_ukończenia_kroku,
Zatwierdzone_przez,
W_Zastępstwie,
Data_akceptacji
FROM
RankedHistory
WHERE
RowNum = 1
ORDER BY
Data_akceptacji DESC;
[/code]

2 for action:
[code]
SELECT
WFH_ID AS ID_of_history,
WFH_TransitionReason,
WFH_STPID AS Krok_ID,
WFH_FinishDurationDateTime AS Data_ukończenia_kroku,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
dbo.clearwfelem(WFH_LeftBy) AS Zatwierdzone_przez,
dbo.clearwfelem(WFH_LeftByImpersonator) AS W_Zastępstwie,
FORMAT(
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END, 'dd.MM.yyyy HH:mm:ss'
) AS Data_akceptacji
FROM
(SELECT
WFH_ID,
WFH_TransitionReason,
WFH_STPID,
WFH_FinishDurationDateTime,
WFH_LeaveCurrentStepPath,
WFH_LeaveCurrentStepDate,
WFH_IsLastVersionInCurrentStep,
WFH_Impersonator,
WFH_LeftBy,
WFH_LeftByImpersonator,
ROW_NUMBER() OVER (
PARTITION BY dbo.clearwfelem(WFH_LeftBy)
ORDER BY
CASE
WHEN WFH_LeaveCurrentStepDate IS NULL THEN WFH_FinishDurationDateTime
ELSE WFH_LeaveCurrentStepDate
END DESC
) AS RowNum
FROM WFHistoryElements
WHERE
WFH_OrgID = {WFD_ID}
AND WFH_STPID = {ST:369}
AND WFH_IsLastVersionInCurrentStep <> ''
) AS RankedHistory
WHERE
RowNum = 1
ORDER BY
Data_akceptacji DESC;
[/code]

Hi Paweł,
at first i'd recommend using the default save button at the menu bar - it keeps the history more tidy, and doesn't trigger step leave / step enter.

Also, when assigning a task for multiple users, they all should just press some 'Approve'/'Disapprove' button, rather than 'Save'.
Save doesn't mean it's approved.

From my perspective those adjustments should make filtering out what is important easier. If approval is done only by 'Approve' path, then just filter out those paths.
Save seems like multi-purpose path at this moment and this leads to confusion both for users and future developers/maintainers.

For unfinished tasks you could join WFHistoryElements with WFElementTasks (it's a view), on WFH_ID = WFT_WFHID, this will give you also tasks which are assigned, but not finished.

Did you know that with WEBCON you can automate virtually any process? Even baking cookies 🍪
 
Speaking of cookies: we use the ones that are essential for our website to function properly, as well as additional ones that help us customize our content to your preferences. If you don’t mind cookies, click Accept. If you want to learn more, explore settings.
Settings