最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

在运行时创建送货地址[Dynamics 365 FO] / Create delivery address run time [Dynamics 365 FO]

网络文摘 William 179浏览 0评论
Folk, Here is quick code to create the delivery address on runtime. You can use this on Purchase Requisition, Purchase order or a person. So we are going to use LogisticsPostalAddressEntity to get the right address with a new one or an existing one. This code should also handle if there is any update in any existing record by updating effective date stamp. Have a look on below code, Public static LogisticsPostalAddressRecId createAddress(tmpNewAddress  _tmpNewAddress) { LogisticsPostalAddress          deliveryAddress; LogisticsPostalAddressEntity    postalAddressEntity; LogisticsPostalAddressView      addressView; DirPartyPostalAddressView       partyAddressView; // get location from current user setup LogisticsLocation           logisticsLocation = LogisticsLocation::find(HcmWorkerTitle::findByWorker(curUserId()).Location); //Address type default to delivery LogisticsLocationRole       logisticsLocationRole = LogisticsLocationRole::findBytype(LogisticsLocationRoleType::Delivery); CompanyInfo                 companyInfo = CompanyInfo::findRecId(‘USMF’); //you may need to get if from current logged in user. //if current user doesn't have setup for location try to get it from LogisticsLocationDefault class if (!logisticsLocation) { HcmWorker hcmWorker = HcmWorker::find(HcmWorker::userId2Worker(curUserId())); logisticsLocation = LogisticsLocationDefault::findSimpleDefault(hcmWorker, logisticsLocationRole); } //if location is still empty get it from companyInfo if (!logisticsLocation) { logisticsLocation = LogisticsLocationDefault::findSimpleDefault(companyInfo, logisticsLocationRole); } //Below code to set buffer with the new address values deliveryAddress.clear(); deliveryAddress.initValue(); deliveryAddress.CountryRegionId = SysUserInfo::find().DefaultCountryRegion; deliveryAddress.Street = _tmpNewAddress.streetAddress; //add other fields in same way partyAddressView.initFromPostalAddress(deliveryAddress); partyAddressView.LocationName = logisticsLocation.Description; postalAddressEntity = LogisticsPostalAddressEntity::construct(); addressView.initFromPartyPostalAddressView(partyAddressView); deliveryAddress = postalAddressEntity.createPostalAddress(addressView); return deliveryAddress.RecId; //return the LogisticsPostalAddress table recId which directly can flow in respective table. } Give a try and share your feedback. Cheers!!! Harry.
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址