Hello everyone,
Today I came across a requirement for Creating and Releasing a Product in D365 FO. Earlier version Ax 2012 has a lot of class's to achieve the requirement but those got deprecated and below is the new way(at least for me) to achieve the requirement.
Args args;EcoResProductEntity ecoResProductEntity;
EcoResProductEntityToCrossTableDataAdaptor adaptor;
EcoResProduct product;
EcoResProductReleaseSessionManager productReleaseSessionManager;
EcoResReleaseSessionRecId releaseSessionRecId;
NumberSequenceReference numberSequenceReference = EcoResProductParameters::numRefProductNumber();
NumberSequenceTable numberSequenceTable = numberSequenceReference.numberSequenceTable();
NumberSeq numberSeq = NumberSeq::newGetNumFromId(numberSequenceTable.RecId);
CompanyInfo companyInfo = CompanyInfo::find();
ecoResProductEntity.clear();
ecoResProductEntity.ProductNumber = 'Testing555';//numberSeq.num();
ecoResProductEntity.ProductSearchName = "myItem";
ecoResProductEntity.ProductName = "My Item";
ecoResProductEntity.ProductType = EcoResProductType::Item;
ecoResProductEntity.ProductSubType = EcoResProductSubtype::ProductMaster;
ecoResProductEntity.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
ecoResProductEntity.ProductDimensionGroupName = "Blank";
ecoResProductEntity.StorageDimensionGroupName = "SiteWHLoc";
ecoResProductEntity.TrackingDimensionGroupName = "None";
// 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();
}
Info(ecoResProductEntity.ProductNumber);
ttscommit;
Proud to be a DAX developer :-)
ecoResProductEntity.ProductNumber = 'Testing555';//numberSeq.num();
ecoResProductEntity.ProductSearchName = "myItem";
ecoResProductEntity.ProductName = "My Item";
ecoResProductEntity.ProductType = EcoResProductType::Item;
ecoResProductEntity.ProductSubType = EcoResProductSubtype::ProductMaster;
ecoResProductEntity.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
ecoResProductEntity.ProductDimensionGroupName = "Blank";
ecoResProductEntity.StorageDimensionGroupName = "SiteWHLoc";
ecoResProductEntity.TrackingDimensionGroupName = "None";
// 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();
}
Info(ecoResProductEntity.ProductNumber);
ttscommit;
Proud to be a DAX developer :-)
No comments:
Post a Comment