我猜想使用 AX 2012 更容易使用 X++ 代码创建和发布产品,但使用 AX7(或者如果您愿意,也可以使用动态 365)获得相同的结果是可能的。
这个想法是使用产品数据实体(即EcoResProductEntity
)和一些标准的——长命名的——类。
这是代码:
EcoResProductEntity ecoResProductEntity;
EcoResProductEntityToCrossTableDataAdaptor adaptor;
EcoResProduct product;
NumberSequenceReference numberSequenceReference = EcoResProductParameters::numRefProductNumber();
NumberSequenceTable numberSequenceTable = numberSequenceReference.numberSequenceTable();
Args args;
NumberSeq numberSeq = NumberSeq::newGetNumFromId(numberSequenceTable.RecId);
EcoResProductReleaseSessionManager productReleaseSessionManager;
EcoResReleaseSessionRecId releaseSessionRecId;
CompanyInfo companyInfo = CompanyInfo::find();
ecoResProductEntity.ProductNumber = numberSeq.num();
ecoResProductEntity.ProductSearchName = "myItem";
ecoResProductEntity.ProductName = "My Item";
ecoResProductEntity.ProductType = EcoResProductType::Item;
ecoResProductEntity.ProductSubType = EcoResProductSubtype::ProductMaster;
ecoResProductEntity.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
ecoResProductEntity.ProductDimensionGroupName = "Prod_Dim";
// here you can set all the fields of the data entity that you need
adaptor = EcoResProductEntityToCrossTableDataAdaptor::newFromEntity(ecoResProductEntity);
ttsbegin;
product = EcoResProductCrossTableManager::makeProductRecord(adaptor);
EcoResProductCrossTableManager::insert(adaptor, product);
// here you can create one or more translations
EcoResProductTranslation::createOrUpdateTranslation(product.RecId, "it translation", '', "it");
// now we want to release that master product for the current company
productReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();
releaseSessionRecId = productReleaseSessionManager.parmReleaseSessionRecId();
productReleaseSessionManager.addProduct(product.RecId);
productReleaseSessionManager.addLegalEntityForProduct(companyInfo.RecId, product.RecId);
args = new Args(formStr(EcoResProductRelease));
args.record(EcoResReleaseSession::find(releaseSessionRecId));
// the first boolean parameter is for showing a log for errors
// the second boolean parameter is for executing the release with a batch
if (EcoResProductReleaseSessionBatch::runJob(args, true, false))
{
productReleaseSessionManager.cleanUp();
}
ttscommit;
我希望它可以帮助你