前言
需求:使用自建表中的数据,然后上传附件,并使用X++代码调用附件作为模板以供使用
实现构思:
1.自建表Table
2.给Table表创建窗体Form,用于展示数据
3.在Form中模仿SalesTable这个窗体中的附件,也添加一个用于创建附件的按钮
4.在Table表中创建记录,在对应的记录中上传附件然后使用X++代码调用相关记录中的附件。
实现方法
一、创建表添加附件
1.创建表
创建一个名为TestAttachments的表
添加一个名为templateRecord的字段,用于标识模板
2.修改Relation
找到DocuRef表并创建扩展,
添加一个Relaion,命名为TestAttachments,修改属性:
Table:选择TestAttachments
Validate:No
EntityRelationShipRole:Refers to
RelatedTableCardinality:ZeroOne
Cardinality:ZeroMore
RelationshipType:Aggregation
UseDefaultRoleNames:Yes
- 1
- 2
- 3
- 4
- 5
- 6
- 7
在关系下添加标准:
设置表关系三个,分别为:
DocuRef.RefRecid == TestAttachments.RecId
DocuRef.RefTableId == TestAttachments.TableId
DocuRef.RefCompanyId == TestAttachments.dataAreaId
- 1
- 2
- 3
3.创建窗体
1.使用TestAttachments表作为数据源,创建一个名为TestAttachments的窗体,
2.在窗体的Designs下的ActionPane中的ActionPaneTab中的ButtonGroup下添加一个CommandButton
3.修改这个CommandButton的属性:
HierarchyParent:值为父控件的name值
Text:显示文本值
ButtonDsiplay:Text & image above
NormalImage:10442
ImageLocation:EmbeddedResource
ShowShortCut:NO
Big:yes
Primary:Yes
NeedsRecord:Yes
Command:文档处理
ToggleButton:Check
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
4.将相关的字段添加到Grid中绑定数据源
到此处给自建表上传附件就完成了,
下面为使用X++调用这个表中指定数据的附件
二.X++代码调用
1.查找出TestAttachments表中的一条记录
select firstonly Recid
from TestAttachments
where TestAttachments.templateRecord == ‘指定值’
2.根据TestAttachments中的Recid查找DocuRef中的记录
select firstonly DocuRef
where DocuRef.RefRecid == TestAttachments.Recid
3.调用方法completeFilename()即可获得附件DocuRef.completeFilename();
三、附件修改
在窗体上点击附件,删除原来的附件,再重新创建一个