Axapta AX 365使用x+创建产品+;代码

Axapta AX 365使用x+创建产品+;代码,axapta,product,x++,dynamics-ax7,dynamics-365-operations,Axapta,Product,X++,Dynamics Ax7,Dynamics 365 Operations,在AX 2012中,我们使用一些类通过编码轻松创建产品和产品主控形状,如: ecoresProductService = EcoResProductService::construct(); ecoResEcoResProduct = new EcoResEcoResProduct(); distintMaster = new EcoResEcoResProduct_Product_Distinct(); 这些类在AX 365中不存在。我需要通过编码创建发布的产品。

在AX 2012中,我们使用一些类通过编码轻松创建产品和产品主控形状,如:

 ecoresProductService  = EcoResProductService::construct();
 ecoResEcoResProduct   = new EcoResEcoResProduct();
 distintMaster         = new EcoResEcoResProduct_Product_Distinct();

这些类在AX 365中不存在。我需要通过编码创建发布的产品。如果您知道如何创建,请与我们分享。提前感谢。

我想使用AX 2012,使用X++代码创建和发布产品会更容易,但使用AX7(或dynamics 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;

我希望它能帮助您

谢谢。此解决方案非常适合创建发布的产品。我首先尝试了这个方法,但发现“EcoRespProductentityToCrossTableDataAdapter”实现了一个接口“EcoRespProductCrossTableData”。如果我们研究“EcoRespProductentityToCrossTableDataAdapter”类的实现,我们会发现许多重要的parm方法都不允许被调用。实现该方法以抛出错误。因此,只剩下一个选择,即自己实现接口“EcoresisProductCrossTableData”。我做到了,工作起来很有魅力

您好@Yasir,我知道
ecoresproductentitytocrosstabledataadapter
类中的一些参数无法调用,但是我可以问一下您指的是哪一个(或者可能是哪一个)?通过在
EcoResProductEntity
中设置相应的值,可能可以获得相同的结果。