如何在网格视图中显示默认值

How to display default values in grid view

我想在 acumatica 基本屏幕“CR306000”ex:attributes 选项卡

的网格视图中显示默认值

我需要编写什么代码才能实现此目的?

答案 1(属性)

您在问题中显示的屏幕是 Acumatica 的一个非常特殊的功能,称为属性。属性被分配给“Classes”,例如库存项目的项目 Class。要在屏幕中添加其他属性,首先要在“属性”屏幕 (CS2050000) 上定义属性,然后将其添加到要使用它的 object 的每个 Class 中。对于您的屏幕截图,这将是 Case Classes (CS206000)。定义 class 后,您可以转到“属性”选项卡添加您定义的与此 class 相关的属性。 (例如,泵的项目 Class 可能包含马力作为属性,但办公用品的项目 Class 则不会。)

将使用属性的功能添加到自定义屏幕需要:

  1. 正在建立您的自定义主记录 (header) 将使用的自定义 Class DAC,
  2. 将 ClassID 字段添加到您的主 DAC 以存储 Class,并且
  3. 定义视图、选项卡和网格,以编辑属性值。

这是一个 link 问题,我是从哪里学会的。包含代码示例,并记录了对我的问题的修复。 How do I enable custom attributes? (can assign on class, but not displaying for transaction)

答案 2(Master-Detail 默认详细信息)

如果您是 Acumatica 开发的新手,您应该先完成他们提供的免费培训课程。这些可以在 Acumatica 网站上的 https://openuni.acumatica.com/courses/development/ 找到。您要针对此案例查看的具体课程是 T210 定制表格和 Master-Detail 关系。在当前培训 material 第 99 页的第 4.2 节中,您将找到一个显示在创建新的 service-device 对记录时预填充“默认保修”的示例的部分。在培训课程中创建的记录和所有自定义,仅作为示例。

实际上,您必须为培训指南中的示例做 2 件事。首先,您创建一个“默认记录”。在培训指南中,您定义了一条保修记录,默认情况下该记录将关联到您的 service-device 记录。接下来,您创建一个事件处理程序,以便在创建 header 中的 parent 时实际填充详细信息选项卡中的网格。培训指南展示了如何执行所有这些操作,但重点是……使用 RowInserted 事件创建详细记录。培训指南中的示例如下:

//Insert the default detail record.
protected virtual void _(Events.RowInserted<RSSVRepairPrice> e)
{
    if (Warranty.Select().Count == 0)
    {
        bool oldDirty = Warranty.Cache.IsDirty;

        // Retrieve the default warranty.
        Contract defaultWarranty = (Contract)DefaultWarranty.Select();
        if (defaultWarranty != null)
        {
            RSSVWarranty line = new RSSVWarranty();
            line.ContractID = defaultWarranty.ContractID;

            // Insert the data record into
            // the cache of the Warranty data view.
            Warranty.Insert(line);

            // Clear the flag that indicates in the UI whether the cache
            // contains changes.
            Warranty.Cache.IsDirty = oldDirty;
        }
    }
}

其中的关键部分是定义记录 (RSSVWarranty line = ...),然后将其插入到与网格关联的视图中 (Warranty.Insert(line);) 示例的其余部分利用特殊视图从保修主 table(合同)获取默认保修记录。