Aras Innovator 中的 C# 方法返回 null 值

问题描述 投票:0回答:1

我在 Aras Innovator 中有一个 C# 方法(服务器端),可以将项目类型中的一些属性写入 pdf。我最近尝试向 pdf 中的表格添加另一行,类似于添加其他属性的方式,但它默认为占位符或“N/A”,即使该属性具有值。

 string classi = quote.getPropertyAttribute("classification", "keyed_name", "N/A");
 gsarow = gsaTable.AddRow();
 gsarow.Height = "0.6cm";
 gsarow.Cells[0].AddParagraph("Classification");
 gsarow.Cells[0].Format.Alignment = ParagraphAlignment.Right;
 gsarow.Cells[0].Format.Font.Bold = true;
 gsarow.Cells[1].AddParagraph(classi);
 gsarow.Cells[1].Format.Alignment = ParagraphAlignment.Right;

以上就是我补充的全部内容。它当前在 PDF 中返回“分类:N/A”。不知道为什么分类会与获取其他 Aras 属性不同,但我可以看到它是不同的。任何帮助将不胜感激。

我尝试对分类属性的数据类型进行更多研究,因为它不像您设置的其他类型(如字符串和浮点数)那么清晰。

c#
1个回答
0
投票

在 Aras Innovator 中,属性可以根据其类型和配置方式具有不同的行为。分类属性通常是用于对项目进行分类的特殊类型,其行为可能与标准字符串或数字属性不同。通过执行这些步骤,您应该能够确定分类属性默认为“N/A”的原因,并在 PDF 中正确检索和显示其值。

在调试中检查属性值:添加一些调试语句或使用日志记录来确认 quote.getPropertyAttribute("classification", "keyed_name", "N/A") 返回的值。例如:

string classi = quote.getPropertyAttribute("classification", "keyed_name", "N/A");
Innovator.Server.Logger.Info($"Classification value: {classi}");

直接属性访问: 尝试使用 getProperty 直接访问属性,而不是使用 getPropertyAttribute:

string classi = quote.getProperty("classification", "N/A");

以下是如何修改代码以包括调试并尝试访问分类属性的替代方法:

// First, try the getPropertyAttribute method
string classi = quote.getPropertyAttribute("classification", "keyed_name", "N/A");
Innovator.Server.Logger.Info($"Using getPropertyAttribute: Classification value: {classi}");

// If the above method does not yield the expected result, try using getProperty
if (classi == "N/A")
{
    classi = quote.getProperty("classification", "N/A");
    Innovator.Server.Logger.Info($"Using getProperty: Classification value: {classi}");
}

// Add the row to the PDF table
gsarow = gsaTable.AddRow();
gsarow.Height = "0.6cm";
gsarow.Cells[0].AddParagraph("Classification");
gsarow.Cells[0].Format.Alignment = ParagraphAlignment.Right;
gsarow.Cells[0].Format.Font.Bold = true;
gsarow.Cells[1].AddParagraph(classi);
gsarow.Cells[1].Format.Alignment = ParagraphAlignment.Right;

我希望这能解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.