To Find or Update customer primary Address in Ax 2012
2015-06-30 11:24
351 查看
To Find or Update customer primary Address in Ax 2012 you can try following code. Relation between dirpartytable and custtable slightly changed in Ax 2012 so you need to re-learn about this.
static void jay_updateAddress(Args _args) {
container roles;
DirParty dirParty;
DirPartyPostalAddressView addressView;
LogisticsPostalAddress address;
CustTable custtable;
DirPartyLocation partyLocation;
;
ttsBegin;
custtable = Custtable::find("Cust-000025");
address = DirParty::primaryPostalAddress(CustTable.Party); //找到主要地址
address = DirParty::findPostalAddressByRole(CustTable.Party, LogisticsLocationRoleType::Business);
/* 找到第一个地址, 并将第一个地址更新为主要地址
select firstonly address join forupdate partyLocation
where partyLocation.Location == address.Location
&& partyLocation.Party == CustTable.Party;
partyLocation.IsPrimary = NoYes::Yes;
partyLocation.update();
*/
address.City = "沧州";
address.State = "河北省";
addressView.IsPrimary = NoYes::Yes; // this line is valid when update
addressView.Party = CustTable.Party;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business).RecId]; // 地址类型
DirParty.createOrUpdatePostalAddress(addressView,roles);
ttsCommit;
info("xixi");
}
Note: createOrUpdatePostalAddress method is useful for both creating or updating the customer address. if you are providing the existing dirpartyid then it will update the customer address ,in case of new dirpartyid it will create a new address.
static void jay_updateAddress(Args _args) {
container roles;
DirParty dirParty;
DirPartyPostalAddressView addressView;
LogisticsPostalAddress address;
CustTable custtable;
DirPartyLocation partyLocation;
;
ttsBegin;
custtable = Custtable::find("Cust-000025");
address = DirParty::primaryPostalAddress(CustTable.Party); //找到主要地址
address = DirParty::findPostalAddressByRole(CustTable.Party, LogisticsLocationRoleType::Business);
/* 找到第一个地址, 并将第一个地址更新为主要地址
select firstonly address join forupdate partyLocation
where partyLocation.Location == address.Location
&& partyLocation.Party == CustTable.Party;
partyLocation.IsPrimary = NoYes::Yes;
partyLocation.update();
*/
address.City = "沧州";
address.State = "河北省";
addressView.IsPrimary = NoYes::Yes; // this line is valid when update
addressView.Party = CustTable.Party;
addressview.initFromPostalAddress(address);
DirParty = DirParty::constructFromPartyRecId(CustTable.Party);
roles = [LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Business).RecId]; // 地址类型
DirParty.createOrUpdatePostalAddress(addressView,roles);
ttsCommit;
info("xixi");
}
Note: createOrUpdatePostalAddress method is useful for both creating or updating the customer address. if you are providing the existing dirpartyid then it will update the customer address ,in case of new dirpartyid it will create a new address.
相关文章推荐
- 代码实现android手机信号监听
- Android高效显示图片详解(二)
- springMVC+Hibernate的配置
- What is Complex Event Processing? (Part 1)
- dubbo+zookeeper小例子
- Android系列---JSON数据解析
- Shell脚本学习
- 2015-06-29
- 深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
- ArduinoYun教程之Arduino编程环境搭建
- 安卓有道词典开发实例
- Nagios 监控redis
- 06-图7. How Long Does It Take (25)
- easyui-datagrid高度放大或缩小动态设置分页参数
- Jquery操作DOM
- window命令修改ip,dns,查看适配器名称
- Python读写Redis数据库
- pip指定安装包版本
- Win7右击计算机管理打不开,提示找不到文件或没有关联的程序
- spring JPA使用