AML 查询
AML(Aras Markup Language)是 Innovator 平台的专有命令语言,基于 XML 结构。所有客户端与服务端、服务端与数据库之间的数据交互都通过 AML 传递。掌握 AML 是进行 Method 开发和系统集成的基础。
AML 基本结构
一条 AML 命令由 <AML> 根元素包裹一个或多个 <Item> 子元素构成:
xml
<AML>
<Item type="Part" action="get">
<item_number>P-10023</item_number>
</Item>
</AML>在 Method 代码中,通常不需要手动拼接 XML 字符串,而是通过 IOM API 链式调用生成等价的 AML 结构。
Item 标签属性
<Item> 标签的属性决定了这条命令对哪种数据执行什么操作:
| 属性 | 说明 |
|---|---|
| type | 目标 ItemType 的名称(如 Part) |
| action | 执行的操作:get / add / edit / update / delete / purge / merge / lock / unlock 等 |
| id | 目标 Item 的 GUID,用于定位具体记录 |
| select | 指定返回的属性列表(逗号分隔),减少数据传输量 |
| orderBy | 结果排序字段 |
| page | 分页:返回第几页 |
| pagesize | 分页:每页行数 |
| maxRecords | 最大返回记录数 |
| where | 自定义 SQL WHERE 子句(高级用法) |
| levels | 关系展开层级 |
| serverEvents | 是否触发服务端事件(0 禁用,1 启用) |
| language | 多语言属性的语言标识(* 表示全部) |
| version | 是否查询已版本化的记录 |
| queryType | 查询模式:Latest(最新版本)/ Released(已发布版本)/ Effective(生效版本) |
| related_expand | 0:related_id 返回 ID;1:展开返回关联 Item 的属性 |
常用 Action 详解
get — 查询
xml
<Item type="Part" action="get" select="item_number,name,cost">
<item_number>P-10023</item_number>
</Item>查询条件默认为 AND 关系,即所有子元素都必须匹配。
add — 创建
xml
<Item type="Part" action="add">
<item_number>P-2026-999</item_number>
<name>新增集成零件</name>
<cost>150.00</cost>
</Item>edit — 编辑
xml
<Item type="Part" action="edit" id="ABCDEF1234567890ABCDEF1234567890">
<cost>200.00</cost>
</Item>edit 必须指定 id 来定位记录。
update — 批量更新
update 可以不指定 id,通过查询条件批量更新匹配的记录。
delete / purge — 删除
- delete:逻辑删除(标记删除)
- purge:物理删除(从数据库中彻底移除)
lock / unlock — 锁定
- lock:锁定 Item,阻止其他用户编辑
- unlock:解除锁定
查询条件
条件运算符
在子元素上通过 condition 属性指定比较方式:
| 运算符 | 说明 | 示例 |
|---|---|---|
eq | 等于(默认) | <name condition="eq">Peter</name> |
ne | 不等于 | <name condition="ne">Peter</name> |
gt | 大于 | <cost condition="gt">200</cost> |
ge | 大于等于 | <cost condition="ge">200</cost> |
lt | 小于 | <cost condition="lt">200</cost> |
le | 小于等于 | <cost condition="le">200</cost> |
like | 模糊匹配(支持 % 通配符) | <name condition="like">Admin%</name> |
not like | 不匹配 | <name condition="not like">%test%</name> |
between | 区间 | <cost condition="between">10 and 90</cost> |
in | 枚举 | <name condition="in">'Admin','Peter'</name> |
is null | 为空 | <name condition="is null" /> |
is not null | 不为空 | <name condition="is not null" /> |
日期查询
Aras 的日期格式为 yyyy-mm-ddThh:mm:ss:
xml
<created_on condition="ge">2024-01-01</created_on>
<modified_on condition="lt">2024-06-01T12:00:00</modified_on>组合条件(AND / OR)
多个子元素默认为 AND 关系。使用 <and> 和 <or> 标签实现 OR 逻辑:
xml
<Item type="Part" action="get">
<or>
<and>
<cost condition="le">35</cost>
<weight condition="le">10</weight>
<make_buy>Make</make_buy>
</and>
<and>
<cost condition="le">100</cost>
<weight condition="le">15</weight>
<make_buy>Buy</make_buy>
</and>
</or>
</Item>使用 <not> 标签取反:
xml
<not>
<state>Released</state>
</not>关系查询
查询关联的子 Item
在 <Item> 内嵌套 <Relationships> 标签,查询 Source Item 的关系记录:
xml
<Item type="Part" action="get" select="item_number">
<item_number>P-10023</item_number>
<Relationships>
<Item type="Part BOM" action="get" select="quantity">
<related_id>
<Item type="Part" action="get" select="item_number,name" />
</related_id>
</Item>
</Relationships>
</Item>通过关系反向查询(Where Used)
通过 related_id 反查哪些父 Item 引用了目标 Item:
xml
<Item type="Part BOM" action="get">
<related_id>
<Item type="Part" action="get">
<item_number>P-10023</item_number>
</Item>
</related_id>
</Item>查询 Item 的外键关联信息
查询包含 created_by_id 等外键属性的关联对象信息:
xml
<Item type="Part" action="get" select="item_number,created_by_id">
<created_by_id>
<Item type="User" action="get">
<last_name>Admin</last_name>
</Item>
</created_by_id>
</Item>分页与排序
xml
<Item type="Part" action="get"
select="item_number,name"
orderBy="item_number"
page="1"
pagesize="10">
</Item>使用 IOM API 构建 AML
在 Server Method 中,通过 IOM 对象链式调用生成 AML,比手动拼接 XML 更安全、更易维护:
csharp
Innovator inn = this.getInnovator();
// 构建查询
Item query = inn.newItem("Part", "get");
query.setAttribute("select", "item_number,name,cost");
query.setProperty("item_number", "P-10023");
// 执行并获取结果
Item result = query.apply();
if (result.isError())
{
return inn.newError("查询失败:" + result.getErrorDetail());
}
string name = result.getProperty("name");
string cost = result.getProperty("cost");对于关系查询:
csharp
Item partQuery = inn.newItem("Part", "get");
partQuery.setProperty("item_number", "P-10023");
Item bomRel = inn.newItem("Part BOM", "get");
bomRel.setAttribute("select", "quantity");
bomRel.setPropertyAttribute("related_id", "select", "item_number,name");
partQuery.addRelationship(bomRel);
Item result = partQuery.apply();AML Studio 调试工具
Aras 提供了 AML Studio 工具(可从 Aras 社区下载),用于在不写代码的情况下测试和调试 AML 命令:
- Log On Settings:配置 Innovator 服务器 URL、数据库 ID 和用户凭据
- AML Request:输入 AML 命令(支持 Ctrl+T 格式化)
- Submit Request:发送到服务器执行
- AML Response:查看服务器返回的 XML 结果
另外,Innovator 内置的 NASH 调试页面也可用于查看 AML 请求和响应:
http://[server]/[InnovatorAlias]/Client/Scripts/Nash.aspx