1. 用[程式片段]定位線上進行中所有的表單版號
DECLARE @CODE NVARCHAR(4000) = '[要尋找的程式片段]';
SELECT
DISTINCT FormDefinition.id,
FormDefinition.version,
FormDefinition.formDefinitionName,
CAST(FormDefinition.script AS NVARCHAR(MAX)) AS script,
'進行中' AS status
FROM
ProcessInstance
INNER JOIN LocalRelevantData ON LocalRelevantData.containerOID = ProcessInstance.contextOID
INNER JOIN FormInstance ON FormInstance.OID = LocalRelevantData.valueOID
INNER JOIN FormDefinition ON FormDefinition.OID = FormInstance.definitionOID
WHERE
ProcessInstance.currentState IN (0, 1, 2)
AND FormDefinition.script LIKE '%' + @CODE + '%'
UNION
SELECT
id,
version,
formDefinitionName,
CAST(FormDefinition.script AS NVARCHAR(MAX)) AS script,
'最新版' AS status
FROM
FormDefinition
WHERE
publicationStatus = 'RELEASED'
AND FormDefinition.script LIKE '%' + @CODE + '%';