Thursday, 20 February 2014

Send Email from Outlook in AX

static void DemoOutlookEmail(Args _args)
{
    SmmOutlookEmail smmOutlookEmail = new SmmOutlookEmail();
    ;
    if (smmOutlookEmail.createMailItem())
    {
        smmOutlookEmail.addEMailRecipient('abc@xyz.in');
        smmOutlookEmail.addSubject("Test");
        smmOutlookEmail.isHTML(true);
        smmOutlookEmail.addBodyText('Test');
        smmOutlookEmail.sendEMail(smmSaveCopyofEmail::No);
    }
}

Import And Release Full Description of item from excel in ax 2012

static void NewImport(Args _args)
{
    SysExcelApplication                       xlsApplication;
    SysExcelWorkBooks                         xlsWorkBookCollection;
    SysExcelWorkBook                          xlsWorkBook;
    SysExcelWorksheets                        xlsWorkSheetCollection;
    SysExcelWorksheet                         xlsWorkSheet;
    SysExcelRange                             xlsRange;
    SysExcelCells                             Cells;
    SysExcelCell                              RCell;
    CommaIO                                   inFile;
    int                                       nRow,i;
    DialogField                               dialogPath;
    Dialog                                    dialog;
    Filename                                  filename;

    EcoResProductMaster                       ecoResProductMaster;
    EcoResProductIdentifier                   ecoResProductIdentifier;
    EcoResProductDimensionGroupProduct        ecoResProductDimensionGroupProduct;
    EcoResProductMasterModelingPolicy         ecoResProductMasterModelingPolicy;
    EcoResStorageDimensionGroupProduct        ecoResStorageDimensionGroupProduct;
    EcoResTrackingDimensionGroupProduct       ecoResTrackingDimensionGroupProduct;
    EcoResConfiguration                       ecoResConfiguration;
    EcoResProductMasterConfiguration          ecoResProductMasterConfiguration;
    EcoResDistinctProductVariant              ecoResDistinctProductVariant;
    EcoResProductVariantConfiguration         ecoResProductVariantConfiguration;

    InventTable                               inventTable;
    InventTableModule                         inventTableModule;
    InventItemSetupSupplyType                 inventItemSetupSupplyType;

    EcoResStorageDimensionGroupItem           ecoResStorageDimensionGroupItem;
    EcoResTrackingDimensionGroupItem          ecoResTrackingDimensionGroupItem;

    InventModelGroupItem                      inventModelGroupItem;
    InventItemGroupItem                       inventItemGroupItem;

    InventDim                                 inventDim;
    InventDimCombination                      inventDimCombination;

    PdsCWProduct                              pdsCWProduct;
    EcoResProductDisplayProductNumber         ecoResProductDisplayProductNumber;
    EcoResProductSearchName                   ecoResProductSearchName;
    EcoResProductType                         ecoResProductType;
    EcoResDistinctProduct                     ecoResDistinctProduct;

    //Traslation
    EcoResProductTranslation                  ecoResProductTranslation;
    LanguageId                                LanguageId;
    EcoResProductName                         ecoResProductName;
    EcoResDescription                         ecoResDescription;
    //EcoResProductDimensionGroup
    EcoResProductDimensionGroup               ecoResProductDimensionGroup;
    EcoResProductDimensionGroupName           ecoResProductDimensionGroupName;
    Description                               description;
    //EcoResStorageDimensionGroup
    EcoResStorageDimensionGroup               ecoResStorageDimensionGroup;
    EcoResStorageDimensionGroupName           ecoResStorageDimensionGroupName;
    //Description                               description;
    //EcoResTrackingDimensionGroup
    EcoResTrackingDimensionGroup              ecoResTrackingDimensionGroup;
    EcoResTrackingDimensionGroupName          ecoResTrackingDimensionGroupName;
    //EcoResProductMaster
    RetailColorGroupId                        retailColorGroupId;
    RetailSizeGroupId                         retailSizeGroupId;
    RetailStyleGroupId                        retailStyleGroupId;
    EcoResVariantConfigurationTechnologyType  ecoResVariantConfigurationTechnologyType;
    ;
    dialog = new Dialog("Import");
    dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
    dialog.run();
    if (dialog.run())
    {
        filename = (dialogPath.value());
    }
    inFile = new CommaIO (filename, 'R');
    if (!inFile || infile.status() != IO_Status::Ok )
    {
        throw error (strfmt("@SYS19312",filename));
    }
    try
    {
        xlsApplication          = SysExcelApplication::construct();
        xlsWorkBookCollection   = xlsApplication.workbooks();
        xlsWorkBookCollection.open(filename);
        xlsWorkSheetCollection  = xlsApplication.worksheets();
        xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
        Cells                   = xlsWorkSheet.Cells();
        nRow = 2;
        RCell = Cells.Item(nRow, 1);
        while (RCell.value().bStr() != "")
        {
            ecoResProductDisplayProductNumber = RCell.value().bStr();
            RCell  = Cells.item(nRow,2);
            pdsCWProduct = any2enum( RCell.value().bStr());
            RCell  = Cells.item(nRow,3);
            ecoResProductType =str2enum(ecoresproducttype, RCell.value().bStr());
            RCell  = Cells.item(nRow,4);
            ecoResProductSearchName   = RCell.value().bStr();
            RCell  = Cells.item(nRow,5);
            ecoResProductName   = RCell.value().bStr();
            RCell  = Cells.item(nRow,6);
            ecoResDescription   = RCell.value().bStr();
            RCell  = Cells.item(nRow,7);
            LanguageId   = RCell.value().bStr();
            RCell  = Cells.item(nRow,8);
            ecoResProductDimensionGroupName   = RCell.value().bStr();
            RCell  = Cells.item(nRow,9);
            description = RCell.value().bStr();
            RCell  = Cells.item(nRow,10);
            ecoResStorageDimensionGroupName = RCell.value().bStr();
            RCell  = Cells.item(nRow,11);
            description = RCell.value().bStr();
            RCell  = Cells.item(nRow,12);
            ecoResTrackingDimensionGroupName = RCell.value().bStr();
            RCell  = Cells.item(nRow,13);
            description = RCell.value().bStr();
            RCell  = Cells.item(nRow,14);
            retailColorGroupId = RCell.value().bStr();
            RCell  = Cells.item(nRow,15);
            retailSizeGroupId = RCell.value().bStr();
            RCell  = Cells.item(nRow,16);
            retailStyleGroupId = RCell.value().bStr();
            RCell  = Cells.item(nRow,17);
            ecoResVariantConfigurationTechnologyType = str2enum(ecoResVariantConfigurationTechnologyType, RCell.value().bStr());
            nRow++;
            RCell = Cells.Item(nRow, 1);
        }
        xlsApplication.quit ();
        xlsApplication.finalize ();
        info("Import completed");
    }
    catch( Exception::Error)
    {
        //Close Excel.
        xlsApplication.quit ();
        xlsApplication.finalize ();
        ttsabort;
        info("Unable to process the excel import ");
    }

    try
    {
        //ProductMaster
        ecoResProductMaster.clear();
        ecoResProductMaster.initValue();
        ecoResProductMaster.ProductType = ecoResProductType;
        ecoResProductMaster.DisplayProductNumber = ecoResProductDisplayProductNumber;
        ecoResProductMaster.SearchName = ecoResProductSearchName;
        ecoResProductMaster.VariantConfigurationTechnology = ecoResVariantConfigurationTechnologyType;
        ecoResProductMaster.RetailColorGroupId = retailColorGroupId;
        ecoResProductMaster.RetailSizeGroupId = retailSizeGroupId;
        ecoResProductMaster.RetailStyleGroupId = retailStyleGroupId;
        if (ecoResProductMaster.validateWrite())
        {
            ecoResProductMaster.insert();
            ecoResProductIdentifier.clear();
            ecoResProductIdentifier.initValue();
            ecoResProductIdentifier.ProductNumber = ecoResProductDisplayProductNumber;
            ecoResProductIdentifier.Product = ecoResProductMaster.RecId;
            ecoResProductIdentifier.insert();

            //Product dimension group
            ecoResProductDimensionGroupProduct.clear();
            ecoResProductDimensionGroupProduct.initValue();
            ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);
            ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(ecoResProductDimensionGroupName).RecId;
            if (ecoResProductDimensionGroupProduct.validateWrite())
            {
                ecoResProductDimensionGroupProduct.insert();
            }

            //Storage dimension group
            ecoResStorageDimensionGroupProduct.clear();
            ecoResStorageDimensionGroupProduct.initValue();
            ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;
            ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(ecoResStorageDimensionGroupName).RecId;
            if (ecoResStorageDimensionGroupProduct.validateWrite())
            {
                ecoResStorageDimensionGroupProduct.insert();
            }

            //Tracking dimension group
            ecoResTrackingDimensionGroupProduct.clear();
            ecoResTrackingDimensionGroupProduct.initValue();
            ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;
            ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(ecoResTrackingDimensionGroupName).RecId;
            if (ecoResTrackingDimensionGroupProduct.validateWrite())
            {
                ecoResTrackingDimensionGroupProduct.insert();
            }

            //Product modeling policy
            ecoResProductMasterModelingPolicy.clear();
            ecoResProductMasterModelingPolicy.initValue();
            ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId;
            if (ecoResProductMasterModelingPolicy.validateWrite())
            {
                ecoResProductMasterModelingPolicy.insert();
            }

            //Product translation
            EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, ecoResProductName, ecoResDescription);

            //Configuration
            ecoResConfiguration = EcoResConfiguration::findByName(description);
            if (!ecoResConfiguration)
            {
                ecoResConfiguration.clear();
                ecoResConfiguration.initValue();
                ecoResConfiguration.Name = description;
                ecoResConfiguration.insert();
            }

            //Configuration assigned to product master
            ecoResProductMasterConfiguration.clear();
            ecoResProductMasterConfiguration.initValue();
            ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
            ecoResProductMasterConfiguration.Description = description;
            ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
            ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;
            ecoResProductMasterConfiguration.insert();

            //Product variant
            ecoResDistinctProductVariant.clear();
            ecoResDistinctProductVariant.initValue();
            ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
            ecoResProductMaster.productNumber(),
            EcoResProductVariantDimValue::getDimensionValuesContainer(description, "", ""));
            ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName + ecoResProductSearchName/*ConfigId*/;
            ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
            ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
            ecoResDistinctProductVariant.insert();

            //Product variant configuration
            ecoResProductVariantConfiguration.clear();
            ecoResProductVariantConfiguration.initValue();
            ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
            ecoResProductVariantConfiguration.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
            ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
            ecoResProductVariantConfiguration.insert();

            //Product variant translation
            EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId, ecoResProductName, ecoResDescription);

            //Released product
            inventTable.clear();
            inventTable.initValue();
            inventTable.initFromEcoResProduct(ecoResProductMaster);
            inventTable.ItemId = ecoResProductDisplayProductNumber;
            inventTable.NameAlias = ecoResProductSearchName;
            if (inventTable.validateWrite())
            {
                inventTable.insert();
                //Inventory model group
                inventModelGroupItem.clear();
                inventModelGroupItem.initValue();
                inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                inventModelGroupItem.ItemId = inventTable.ItemId;
                inventModelGroupItem.ModelGroupId = "FIFO";
                inventModelGroupItem.ModelGroupDataAreaId = curext();
                inventModelGroupItem.insert();

                //Item group
                inventItemGroupItem.clear();
                inventItemGroupItem.initValue();
                inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                inventItemGroupItem.ItemId = inventTable.ItemId;
                inventItemGroupItem.ItemGroupId = "Parts";
                inventItemGroupItem.ItemGroupDataAreaId = curext();
                inventItemGroupItem.insert();

                //Extended product details - Inventory
                inventTableModule.clear();
                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
                inventTableModule.insert();

                //Extended product details - Purchase
                inventTableModule.clear();
                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
                inventTableModule.insert();

                //Extended product details - Sales
                inventTableModule.clear();
                inventTableModule.initValue();
                inventTableModule.ItemId = inventTable.ItemId;
                inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
                inventTableModule.insert();

                //Warehouse items
                InventItemLocation::createDefault(inventTable.ItemId);

                //Supply type setup
                inventItemSetupSupplyType.clear();
                inventItemSetupSupplyType.initValue();
                inventItemSetupSupplyType.ItemId = inventTable.ItemId;
                inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
                inventItemSetupSupplyType.insert();

                //Product storage dimension group
                ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);

                if (ecoResStorageDimensionGroupProduct.RecId)
                {
                    ecoResStorageDimensionGroupItem.clear();
                    ecoResStorageDimensionGroupItem.initValue();
                    ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                    ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
                    ecoResStorageDimensionGroupItem.StorageDimensionGroup   = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
                    ecoResStorageDimensionGroupItem.insert();
                }

                //Product tracking dimension group
                ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
                if (ecoResTrackingDimensionGroupProduct.RecId)
                {
                    ecoResTrackingDimensionGroupItem.clear();
                    ecoResTrackingDimensionGroupItem.initValue();
                    ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                    ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
                    ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
                    ecoResTrackingDimensionGroupItem.insert();
                }
            }
            inventDim.clear();
            inventDim.ConfigId = description;/*ConfigId*/
            inventDim = InventDim::findOrCreate(inventDim);

            //Released product variant
            inventDimCombination.clear();
            inventDimCombination.initValue();
            inventDimCombination.DistinctProductVariant = ecoResDistinctProductVariant.RecId;
            inventDimCombination.ItemId = inventTable.ItemId;
            inventDimCombination.InventDimId = inventDim.InventDimId;
            inventDimCombination.insert();
        }
    }
    catch
    {
        error("Error!");
        return;
    }
    info("Release Done!");
}

Import data from Excel file into EcoResProduct abstract table in ax 2012.

you can't insert any records directly to any abstract class, in the same way as you can't directly instantiate any abstract class. What you can do is to insert data to a concrete child of the abstract table (again, you can see the similarity with classes).
EcoResProduct has three children:
EcoResDistinctProduct, EcoResDistinctProductVariant and EcoResProductMaster.

Write Below Job For this:-
static void RecordsImports(Args _args)
{
    SysExcelApplication                      xlsApplication;
    SysExcelWorkBooks                    xlsWorkBookCollection;
    SysExcelWorkBook                     xlsWorkBook;
    SysExcelWorksheets                    xlsWorkSheetCollection;
    SysExcelWorksheet                     xlsWorkSheet;
    SysExcelRange                            xlsRange;
    SysExcelCells                              Cells;
    SysExcelCell                               RCell;
    CommaIO                                   inFile;
    int                                                nRow,i;
    DialogField                                 dialogPath;
    Dialog                                        dialog;
    Filename                                    filename;
    PdsCWProduct                         pdsCWProduct;
    EcoResProductDisplayProductNumber    ecoResProductDisplayProductNumber;
    EcoResProductSearchName                    ecoResProductSearchName;
    EcoResProductType                                ecoResProductType;
    EcoResDistinctProduct                             ecoResDistinctProduct;
    EcoResDistinctProductVariant                  ecoResDistinctProductVariant;
    EcoResProductMaster                              ecoResProductMaster;
    ;
    dialog = new Dialog("Import");
    dialogPath = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
    dialog.run();
    if (dialog.run())
    {
        filename = (dialogPath.value());
    }
    inFile = new CommaIO (filename, 'R');
    if (!inFile || infile.status() != IO_Status::Ok )
    {
        throw error (strfmt("@SYS19312",filename));
    }
    try
    {
        xlsApplication          = SysExcelApplication::construct();
        xlsWorkBookCollection   = xlsApplication.workbooks();
        xlsWorkBookCollection.open(filename);
        xlsWorkSheetCollection  = xlsApplication.worksheets();
        xlsWorkSheet            = xlsWorkSheetCollection.itemFromNum(1);
        Cells                   = xlsWorkSheet.Cells();
        nRow = 2;
        RCell = Cells.Item(nRow, 1);
        while (RCell.value().bStr() != "")
        {
            ecoResProductDisplayProductNumber = RCell.value().bStr();
            RCell  = Cells.item(nRow,2);
            pdsCWProduct = any2enum( RCell.value().bStr());
            RCell  = Cells.item(nRow,3);
            ecoResProductType =str2enum(ecoresproducttype, RCell.value().bStr());
            RCell  = Cells.item(nRow,4);
            ecoResProductSearchName   = RCell.value().bStr();
                    ecoResDistinctProduct.DisplayProductNumber    = ecoResProductDisplayProductNumber;
                    ecoResDistinctProduct.PdsCWProduct    = pdsCWProduct;
                    ecoResDistinctProduct.ProductType  = ecoResProductType;
                    ecoResDistinctProduct.SearchName = ecoResProductSearchName;

                    ecoResDistinctProductVariant.DisplayProductNumber    =             ecoResProductDisplayProductNumber;
                    ecoResDistinctProductVariant.PdsCWProduct    = pdsCWProduct;
                    ecoResDistinctProductVariant.ProductType  = ecoResProductType;
                    ecoResDistinctProductVariant.SearchName = ecoResProductSearchName;


                    ecoResProductMaster.DisplayProductNumber    = ecoResProductDisplayProductNumber;
                    ecoResProductMaster.PdsCWProduct    = pdsCWProduct;
                    ecoResProductMaster.ProductType  = ecoResProductType;
                    ecoResProductMaster.SearchName = ecoResProductSearchName;
            ecoResProductMaster.insert();
            nRow++;
            RCell = Cells.Item(nRow, 1);
        }
        xlsApplication.quit ();
        xlsApplication.finalize ();
        info("Import completed");
    }
    catch( Exception::Error)
    {
        //Close Excel.
        xlsApplication.quit ();
        xlsApplication.finalize ();
        ttsabort;
        info("Unable to process the excel import ");
    }
}

Add Fields to a table using X++ code

static void createFieldFromCode(Args _args)
{
    #AOT
    TreeNode tableNode;
    AotTableFieldList myAOTTablefieldList;
    SysDictTable sysDictTable = new SysDictTable(tablenum(Table_Test));
    ;
    myAOTTablefieldList = new AotTableFieldList();
    tableNode = TreeNode::findNode(#TablesPath+'\\'+sysDictTable.name());
    myAOTTablefieldList = TreeNode::findNode(#TablesPath+'\\'+sysDictTable.name() + "\\Fields");
    if(!myAOTTablefieldList.AOTfindChild("newField")) // check if the field alredy exists
    {
    myAOTTablefieldList.addString("newField");
    }
    tableNode.AOTsave();
}

How to Create a New Table by using X++ code

static void newTableCreate(Args _args)
{
TreeNode      treeNode;
#AOT
;
treeNode = TreeNode::findNode(#TablesPath);
treeNode.AOTadd("Table_Test");
SqlDataDictionary::synchronize();
}

Tuesday, 11 February 2014

SSRS Report Code in AX 2012

Define Data Contract Class:-
[DataContractAttribute]
public class SrsRDPContractSample
{
    AccountNum accountNum;
    Name       name;
    Phone      phone;
}
[DataMemberAttribute("AccountNum")]
public AccountNum parmAccountNum(AccountNum _accountNum = accountNum)
{
    accountNum = _accountNum;
    return accountNum;
}
[DataMemberAttribute("Name")]
public Name Name (Name _name = name)
{
    name = _name ;
    return name;
}
[DataMemberAttribute("InclTax")]
public Phone phone(Phone_phone = phone)
{
    phone= _phone;
    return phone;
}
Now Define Report Data Provider Class:-
[
    SRSReportQueryAttribute('Cust'),
    SRSReportParameterAttribute(classstr(SrsRDPContractSample))
]
public class SrsRdpSampleClass extends SRSReportDataProviderBase
{
    TmpCustTableSample tmpCust;
}
[SRSReportDataSetAttribute('TmpCust')]
public TmpCustTableSample getTmpCustTable()
{
    select * from tmpCust;
    return tmpCust;
}

public void processReport()
{
    AccountNum              accntNum;
    CustAccountStatement    custAcctStmt;
    boolean                 boolInclTax;
    Query                   query;
    QueryRun                qr;
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    CustTable               queryCustTable;

    SrsRdpContractSample    dataContract;

    // Get the query from the runtime using a dynamic query.
    query = this.parmQuery();
        
    // Get the parameters passed from runtime.
    dataContract = this.parmDataContract();
    accntNum = dataContract.parmAccountNum();
    Name= dataContract.parmName();
    Phone= dataContract.parmPhone();
        
    // Add parameters to the query.
    queryBuildDataSource = query.dataSourceTable(tablenum(CustTable));
        
    if(accntNum)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, AccountNum));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, AccountNum));
        }
        // If an account number has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(accntNum);
    }        
        
    if(name)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, Name));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, Name));
        }
        // If an account statement has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(int2str(name));
    }
        
    if(phone)
    {
        queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, phone));
        if (!queryBuildRange)
        {
            queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, phone));
        }
        // If flag to include tax has not been set, then use the parameter value to set it.
        if(!queryBuildRange.value())
            queryBuildRange.value(phone);
    }        
        
    // Run the query with modified ranges.
    qr = new QueryRun(query);
    ttsbegin;
    while(qr.next())
    {
        tmpCust.clear();
        queryCustTable = qr.get(tablenum(CustTable));
        tmpCust.AccountNum = queryCustTable.AccountNum;
        tmpCust.Name = queryCustTable.name();
        tmpCust.Phone= queryCustTable.phone();
        tmpCust.insert();
    }
    ttscommit;
} 

Job for SSRS Report Debug in ax 2012

static void debugreport(Args _args)
    {
        DebugReportDP   DebugReportDP;
        DebugReportContract DebugReportContract;
        Query               q;
        DebugReportTmp      DebugReportTmp;
        ;
        DebugReportDP = new DebugReportDP();
        DebugReportContract = new DebugReportContract();
        q = new Query(querystr(DebugReportQuery));
        DebugReportDP.parmQuery(q);
        DebugReportDP.parmDataContract(DebugReportContract);
        DebugReportDP.processReport();
        DebugReportTmp = DebugReportDP.getDebugReportTmp();
    }