Acumatica定制项目中的CREATE VIEW语句

时间:2017-10-06 15:32:31

标签: acumatica acumatica-kb

有谁知道如何将CREATE VIEW SQL语句推送到Acumatica自定义项目中?

我知道如何在SQL Management Studio中执行此操作,但通过自定义项目执行此操作对Acumatica SaaS客户非常有用。

1 个答案:

答案 0 :(得分:0)

您应该执行以下步骤:

  1. 在Management Studio中创建SQL视图(出于演示目的,让我坚持使用简单的PositivePay视图):

    CREATE VIEW [dbo].[PositivePay] AS
    SELECT
        APPayment.RefNbr,
        APPayment.ExtRefNbr,
        APRegister.DocDate,
        APRegister.OrigDocAmt,
        CashAccount.ExtRefNbr BankAccountID
    FROM APPayment 
    JOIN APRegister 
        ON APRegister.CompanyID = APPayment.CompanyID 
            AND APRegister.RefNbr = APPayment.RefNbr 
    JOIN CashAccount 
        ON APPayment.CashAccountID = CashAccount.AccountID 
            AND APPayment.CompanyID = CashAccount.CompanyID 
    WHERE APPayment.CompanyID = 2 AND APPayment.DocType= 'CHK'
    GO
    
  2. 打开自定义项目并单击代码,然后根据您的SQL视图生成新的DAC,如下面的屏幕截图所示: enter image description here

  3. 定义新DAC的关键字段并保存更改。对于PositivePay,我们在RefNbr字段顶部为PXDBString属性设置 IsKey true

    [PXDBString(15, IsUnicode = true, InputMask = "", IsKey = true)]
    [PXUIField(DisplayName = "Ref Nbr")]
    public string RefNbr { get; set; }
    
  4. 单击数据库脚本,在数据库名称中选择您的SQL视图名称,并将SQL脚本放入自定义脚本控件中下面的模式:

    IF EXISTS
    (
        SELECT * FROM sys.views
        WHERE name = 'PositivePay' AND schema_id = SCHEMA_ID('dbo')
    )
    DROP VIEW [dbo].[PositivePay]
    GO
    
    CREATE VIEW [dbo].[PositivePay] AS
    SELECT
        APPayment.RefNbr,
        APPayment.ExtRefNbr,
        APRegister.DocDate,
        APRegister.OrigDocAmt,
        CashAccount.ExtRefNbr BankAccountID
    FROM APPayment 
        JOIN APRegister 
            ON APRegister.CompanyID = APPayment.CompanyID 
                AND APRegister.RefNbr = APPayment.RefNbr 
        JOIN CashAccount 
            ON APPayment.CashAccountID = CashAccount.AccountID 
                AND APPayment.CompanyID = CashAccount.CompanyID 
    WHERE APPayment.CompanyID = 2 AND APPayment.DocType= 'CHK'
    GO
    

    enter image description here