This method is used in custom X++ code to automate the product release process.
Normally, product release can also be done manually from the Product Information Management > Released Products > Release Product form.
Using this method allows programmatic, batch, or automated release.
The method supports error logging, so you can trace if a product fails to release.
/// <summary>
/// Release product
/// </summary>
/// <param name = "_ecoResProduct">EcoResProduct</param>
/// <param name = "LegalEntity">DataAreaId</param>
/// <param name = "_materialNumber">String20</param>
/// <param name = "_plantExtension">String10</param>
public void releaseProduct(EcoResProduct _ecoResProduct,DataAreaId LegalEntity,String20 _materialNumber,String10 _plantExtension)
{
Args args;
EcoResProductReleaseSessionManager productReleaseSessionManager;
EcoResReleaseSessionRecId releaseSessionRecId;
CompanyInfo companyInfo = CompanyInfo::find();
// now we want to release that master product for the current company
productReleaseSessionManager = EcoResProductReleaseSessionManager::newReleaseSession();
releaseSessionRecId = productReleaseSessionManager.parmReleaseSessionRecId();
productReleaseSessionManager.addProduct(_ecoResProduct.RecId);
productReleaseSessionManager.addLegalEntityForProduct(companyInfo.RecId, _ecoResProduct.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();
}
}
The EcoResProductReleaseSessionBatch class is responsible for executing a product release session in batch mode.
Find the current company information.
Start a new product release session.
Add the product and the company to this session.
Prepare Args to pass session info to the release form.
Run the release job immediately (or batch mode if needed).
Clean up temporary session data after completion.