2017-04-11 36 views
2

在AX 2012年,我們用於通過編碼通過使用一些類像很容易地創建產品和產品主:AX 365創建X產品++代碼

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

這些類不AX 365存在我需要通過編碼創建發佈的產品。如果你知道如何創建,請分享。提前致謝。

回答

2

我想這與AX 2012是更容易地創建和使用X ++代碼發佈一個產品,但它是不可能性(如果你喜歡或動態365),以獲得與AX7相同的結果。

這個想法是使用產品數據實體(即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; 

我希望它可以幫助你

0

由於伊爾維克這種解決方案非常適合用於製作發佈的產品。我曾嘗試過,但發現「EcoResProductEntityToCrossTableDataAdaptor」實現了一個界面「EcoResIProductCrossTableData」。如果我們通過實施「EcoResProductEntityToCrossTableDataAdaptor」類,我們發現許多重要的parm方法不允許被調用。該方法被實施來拋出錯誤。因此只有一個選擇,自己實現界面「EcoResIProductCrossTableData」。我做了並且像魅力一樣工作。

+0

嗨@Yasir,我知道在'EcoResProductEntityToCrossTableDataAdaptor'類不能被稱爲PARMS一些,但我可以問你哪一個(或可能的),你是什麼意思?可能通過在EcoResProductEntity中設置相應的值來獲得相同的結果。 –