简体   繁体   English

AX 2012中批处理作业状态的可能值和文本描述是什么?

[英]What are the possible values and text description for batch job status in AX 2012?

I'm creating a report to show issues with batch jobs in Microsoft AX 2012, but have been unable to find anything to link the integer status values in the BATCHJOB table in SQL Server to the text description shown in the application. 我正在创建一个报告,以显示Microsoft AX 2012中批处理作业的问题,但无法找到任何内容将SQL Server的BATCHJOB表中的整数状态值链接到应用程序中显示的文本描述。 I was told this should exist in the model database in the enums, but I was unable to determine the proper links between the data in that database. 有人告诉我这应该存在于枚举的模型数据库中,但是我无法确定该数据库中数据之间的正确链接。 I have also been unable to find this information in a web search or any of the documentation provided by Microsoft. 我也无法在网络搜索或Microsoft提供的任何文档中找到此信息。 Is anyone able to supply these values, or tell me where to find them? 有谁能够提供这些值,或者告诉我在哪里可以找到它们?

SELECT bj.[STATUS] AS [bj_STATUS]
    -- 1: Didn't run - what else? 
    -- 2: Canceled - what else?
    -- 3: Error? 
    -- 4: Success?
    -- 5: ?
    -- 6: ?
    -- 7: ?
    -- 8: Withhold?
    -- Waiting
    -- Ended
    -- Withhold
    -- Executing
    -- Ready
    -- Finished
    -- Error
    -- Didn't run
    ,bj.[CAPTION] AS [bj_CAPTION]
    ,bjh.[STARTDATETIME] AS [bjh_STARTDATETIME]
    ,bjh.[ENDDATETIME] AS [bjh_ENDDATETIME]
    ,bjh.[BATCHCREATEDBY] AS [bjh_BATCHCREATEDBY]
    ,bjh.[CANCELEDBY] AS [bjh_CANCELEDBY]
    ,bg.[GROUP_] AS [bg_GROUP]
    ,bg.[DESCRIPTION] AS [bg_DESCRIPTION]
    ,bh.[SERVERID] AS [bh_SERVERID]
FROM [MicrosoftDynamicsAX].[dbo].[BATCHJOB] bj WITH(NOLOCK)
INNER JOIN [MicrosoftDynamicsAX].[dbo].[BATCHJOBHISTORY] bjh WITH(NOLOCK)
    ON bjh.[BATCHJOBID] = bj.[RECID] 
INNER JOIN [MicrosoftDynamicsAX].[dbo].[BATCH] b WITH(NOLOCK)
    ON b.[BATCHJOBID] = bj.[RECID] 
INNER JOIN [MicrosoftDynamicsAX].[dbo].[BATCHGROUP] bg WITH(NOLOCK)
    ON bg.[GROUP_] = b.[GROUPID] 
INNER JOIN [MicrosoftDynamicsAX].[dbo].[BATCHHISTORY] bh WITH(NOLOCK)
    ON bh.[BATCHID] = b.[RECID]
    AND bh.[BATCHJOBID] = bj.[RECID]
    AND bh.[BATCHJOBHISTORYID] = bjh.[RECID]
WHERE bjh.[STARTDATETIME] > GETDATE() - 1 -- AND bj.[STATUS] NOT IN(1, 2, 4)

The enum is BatchStatus , which is stored in the modelstore DB, but I don't think the enum names and/or values are stored. 枚举是BatchStatus ,它存储在模型存储数据库中,但是我不认为存储了枚举名称和/或值。 It represents an integer ultimately. 最终代表整数。

Below is the base enum with the integer values 0-8: 以下是具有0-8整数值的基本枚举:

在此处输入图片说明

The text labels are the same as the name (in English that is) except for the below exceptions. 文本标签与名称相同(英文),但以下情况除外。

  • 0 - Withhold (Hold) 0-预扣(保留)
  • 4 - Ended (Finished) 4-结束(完成)
  • 6 - Didn't run (NotRun) 6-未运行(NotRun)

You could probably just create a SQL stored procedure with a CASE statement as these statuses are rarely changed from base code. 您可能只需要使用CASE语句创建一个SQL存储过程,因为这些状态很少会从基本代码中更改。

I was able to figure out how to get this out of the database thanks to the information provided by @Alex Kwitny. 由于@Alex Kwitny提供的信息,我能够弄清楚如何从数据库中获取此信息。 Once I had the name of the enum, I was able to find it in the ModelElement table and link it back to the ModelElementData table on the ElementHandle value. 一旦有了枚举的名称,就可以在ModelElement表中找到它,并将其链接回ElementHandle值上的ModelElementData表。 The ModelElementData table has a Properties field stored in varbinary that can be broken down into pieces to read the values for each integer value in the main database. ModelElementData表具有存储在varbinary中的“属性”字段,可以将其细分为多个部分,以读取主数据库中每个整数值的值。 It took me a while to parse through everything and convert the binary into text, but now I can just reference the enum values in case anything ever changes in the future by turning my query into a function that can be called from the main query in my report. 我花了一些时间来解析所有内容并将二进制文件转换为文本,但是现在我可以引用枚举值,以防万一将来发生任何更改,方法是将查询转换为可以从主查询中调用的函数报告。

DECLARE @name AS VARCHAR(40) = 'BatchStatus'
      , @value AS INT = 1
      , @language AS VARCHAR(8) = 'en_us';

DECLARE @bin AS VARBINARY(MAX);
SET @bin =
(
    SELECT TOP (1)
           med.[Properties]
    FROM [MicrosoftDynamicsAX_Model].[dbo].[ModelElement] me
        INNER JOIN [MicrosoftDynamicsAX_Model].[dbo].[ModelElementData] med
            ON med.[ElementHandle] = me.[ElementHandle]
    WHERE me.[Name] = @name
          AND me.[ElementType] = 40
    ORDER BY med.[LayerId] DESC
);
DECLARE @pos AS INT;
DECLARE @flags AS INT;
DECLARE @count AS INT;
DECLARE @idx AS INT;
DECLARE @off AS INT;
DECLARE @result AS VARCHAR(255);
SET @pos = 3;
SET @off = CAST(SUBSTRING(@bin, @pos, 1) AS INT) - 1;
SET @pos = @pos + 1;
WHILE @off > 0
BEGIN
    WHILE SUBSTRING(@bin, @pos, 2) <> 0x0000
    SET @pos = @pos + 2;
    SET @pos = @pos + 2;
    SET @off = @off - 1;
END;
SET @flags = CAST(SUBSTRING(@bin, @pos, 3) AS INT);
SET @pos = @pos + 3;
IF @flags & 0x008000 = 0x008000
BEGIN
    WHILE SUBSTRING(@bin, @pos, 2) <> 0x0000
    SET @pos = @pos + 2;
    SET @pos = @pos + 2;
END;
IF @flags & 0x000002 = 0x000002
    SET @pos = @pos + 1;
SET @pos = @pos + 1; 
SET @count = CAST(SUBSTRING(@bin, @pos, 1) AS INT);
IF @count > 0
BEGIN
    SET @pos = @pos + 1;
    IF @flags & 0x000200 = 0x000200
        SET @idx = @value;
    ELSE
    BEGIN
        SET @idx = 0;
        SET @off = 2 + CAST(CAST(REVERSE(SUBSTRING(@bin, @pos, 2)) AS BINARY(2)) AS INT) * 2;
        SET @off = @off + 2 + CAST(CAST(REVERSE(SUBSTRING(@bin, @pos + @off, 2)) AS BINARY(2)) AS INT) * 2;
        WHILE CAST(SUBSTRING(@bin, @pos + @off + @idx, 1) AS INT) <> @value
              AND @idx < @count
        SET @idx = @idx + 1;
        IF CAST(SUBSTRING(@bin, @pos + @off + @idx, 1) AS INT) <> @value
            SET @idx = -1;
    END;
    IF @idx >= 0
    BEGIN
        SET @pos = @pos + 2;
        WHILE 1 = 1
        BEGIN
            SET @off = 0;
            SET @result = '';
            WHILE SUBSTRING(@bin, @pos + @off, 2) <> 0x0000
            BEGIN
                SET @result = @result + CHAR(CAST(REVERSE(SUBSTRING(@bin, @pos + @off, 2)) AS BINARY(2)));
                SET @off = @off + 2;
            END;
            SET @pos = @pos + @off + 2;
            IF @idx <= 0
                BREAK;
            SET @idx = @idx - 1;
        END;
    END;
    ELSE
        SET @result = '~ENUM NOT FOUND~';
END;
ELSE
    SET @result = '~ERROR~';
IF SUBSTRING(@result, 1, 1) = '@'
BEGIN
    DECLARE @module AS VARCHAR(3);
    DECLARE @label AS INT;
    SET @module = SUBSTRING(@result, 2, 3);
    SET @label = CAST(SUBSTRING(@result, 5, DATALENGTH(@result) - 4) AS INT);
    SET @result =
    (
        SELECT TOP (1)
               [Text]
        FROM [MicrosoftDynamicsAX_Model].[dbo].[ModelElementLabel]
        WHERE [LabelId] = @label
              AND [Module] = @module
              AND [Language] = @language
        ORDER BY [LayerId] DESC
    );
END;

SELECT @value AS [Id]
     , @result AS [Status];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM