Search This Blog

Friday, June 15, 2012

AX2012 Apply Template for Product using X++


This following sample code used to get the Template based on the paremeter that was defined and apply that template for the released product.


//this methods is used to retrieve the Templata data based on the Parameter and returns the container of the templateData that will be used in apply template functionality.
private container getTemplateData()
{
    SysRecordTemplateTable  templateTable;
    SysRecordTmpTemplate  tmp;
    container  dataContainer,RecordTmplateData;
    ParameterLocationTable  parameterLocation;
    int i;
    ;
     parameterLocation = ParameterLocationTable   ::find("TestLocation");
    sysRecordTmpTemplate=null;
    if( parameterLocation  )
    {
        select templateTable where templateTable.table==tableNum(inventTable);
        dataContainer=templateTable.Data;
        for (i=conlen(dataContainer); i; i--)
        {
            [tmp.Description, tmp.DefaultRecord, tmp.Data, tmp.Details] = conpeek(dataContainer, i);
            if(tmp.Description== parameterLocation .ItemTemplate)
            {
                tmp.OrgDescription=tmp.Description;
                tmp.insert();
                RecordTmplateData=tmp.data;
            }
        }
    }
    return RecordTmplateData;
}

// apply the Template for the released Product to the company

private void applyTemplate()
{
    EcoResProductTemplateApplyManagerUtils utils;
    InventTable                            inventTable;
    container           recordTmpValues;

   // if Product is released to the company
    if (releaseProductToCompany)
    {
        inventTable = InventTable::Find("Item1");
        recordTmpValues=this.getTemplateData(_changeOrderProduct);
        utils = EcoResProductTemplateApplyManagerUtils::newDefault();
        utils.applyTemplate(
            recordTmpValues,
            inventTable.ItemId);
    }
}

3 comments:

  1. Hi Krishna,

    Can you please let me know whre i have to find ParameterLocationTable that you specified in your code.
    I tried but unable to locate it in the AOT.

    Thanks
    Dinesh

    ReplyDelete
    Replies
    1. Hi Dinesh,
      That was the my custom table where I defined which template i have to use to apply for product, so you can create your owntable where you have to define the template name to use to apply.

      Regards,
      krishna.

      Delete
  2. Hi Krishna,

    How to apply template at the time of product creation..?
    Does your code apply template after the product is created...?

    ReplyDelete

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.