Monday, 21 December 2015

        How to use Event Handler in Microsoft Dynamics AX 2012


1)Open your new developer work space and go to AOT then classes node.

2)Right click on Classes node and click on New Class as shown below.



3) By default system will give a name to it. Here in my case it’s Class1. Right click on newly created class and click on Rename shown below.


4) After clicking Rename, give a name called CustTableEventHandler to it. Here I am going to develop an event to be applied on CustTable so that is the reason why I decided this name (CustTableEventHandler). After renaming this class, it looks as shown below.


5) Right click on class CustTableEventHandler then New then Pre- or post-event handler as shown below.


6) Once you click on this, system gives you a method as shown below.


7) Customize the method as shown below.

8) Here args is providing current record to custTable instance and info is displaying the current customer account. The code snippet is below.

public static void custCreateInfo(XppPrePostArgs _args)
{
     CustTable custTable;
     custTable = _args.getThis();

     info(strFmt("Customer account %1 has been created", custTable.AccountNum));
}

This method I support to call from insert method of CustTable with type post event. It means that once insertion is done to CustTable, system will display recently inserted customer account number. It depends on your business requirement what logic you want to apply here. So here you can develop your required business logic or invoke pre built logic.

9) Go to Tables node in AOT then find out CustTable.

10) Go to insert method of CustTable and right click on it then click on New Event Handler Subscription as shown below.


11) After clicking you will get a new Event handler shown below.


12) Rename the event handler to custCreateInfo and set the property as shown below.


13) Now save your work.

14) Go to Customer form and create a new customer. Here I created a new customer account called “Test-000001”.


15) Once this customer is created system will give your infolog as shown below.


Hope this will help you to understand the event handler in Microsoft Dynamics AX 2012.

 

Tuesday, 15 December 2015

Sales Order and Purchase Order Tables and Classes


SalesOrder Classes and Tables:

SalesTableType and SaleslineType classes will get called while creating the SalesOrders.
SalesFormLetter_Confirm
SalesFormLetter_Invoice
SalesFormLetter_PackingSlip
SalesFormLetter_PickingLlst
classes will be used to post the sales order at various document status (packing, invoice etc).
Tables:
SalesTable contains all SalesOrder headers regardless whether they have been posted or not.
The SalesParmTable and SalesParmLine contains detailed information regarding posting sales headers and Lines.
CustConfirmJour and CustConfirmTrans tables contains all Sales Confirmation headers and Lines posted in Dynamic Ax originating from Sales Orders and Lines.
CustPackingSlipJour and CustPackingSlipTrans tables contains all sales PackingSlip headers and Lines posted in Dynamic Ax originating from Sales Orders and Lines.
CustInvoiceJour and CustInvoiceTrans tables contains all sales all Sales Invoice headers and Lines posted in Dynamic Ax originating from Sales Orders and Lines.

Purchase Order classes and Tables:


PurchTableType and PurchTableLine classes will get called while creating the PurchaseOrders.
PurchFormLetter_PurchOrder
PurchFormLetter_ApproveJournal
PurchFormLetter_Invoice
PurchFormLetter_PackingSlip
PurchFormLetter_ReceiptsList
classes will be used to post the PurchaseOrder at various document status (packing, invoice etc).
Tables:
PurchTable contains all purchase order headers regardless whether they have been posted or not.
PurchParmTable and PurchParmLine contains detailed information regarding posting Purchase headers and Lines.
VendPackingSlipJour and VendPackingSlipTrans tables contains posted packingslip headers and lines.
VendInvoiceJour and VendInvoiceTrans tables contains all invoiced purchase order headers and Lines.
VendReceiptsJour and VendReceiptsTrans tables contains posted receipt header and lines.
VendPurchOrderJour and VendPurchOrderTrans tables contains Purchase requisition headers and lines.

Thursday, 10 December 2015

Passing values between forms

For passing parameters from one form to another a special class Args is usually used. 

Example:

The code of button click event of FormA which calls FormB and passes some parameters to that form. <xpp> void clicked()
{
   // Args class is usually used in Axapta for passing parameters between forms
   Args            args;
   FormRun         formRun;
   // Our custom made class for passing complex set of parameters
   FormBParams     formBParams = new FormBParams();
   Array           items = new Array( Types::String );
   int         i;
   ;
   args = new args();
   // Our values which we want to pass to FormB
   // If we want pass just simple string we can use 'parm' method of 'Args' class
   args.parm( strValue.text() );
   // We also can pass enum value to FormB
   args.parmEnum( NoYesEnumValue.selection() );
   args.parmEnumType( EnumNum( NoYes ) );
   // and also can pass a cursor pointing to some record (in our case it is EmplTable )
   args.record( EmplTable );
   // If we want pass more complex set of parameters we can develop our own class
   // just for passing our parameters.
   formBParams.parmSomeDate( someDate.dateValue() );
   formBParams.parmSomeTime( someTime.value() );
   for( i=0; i<ListBox.items(); i++ )
   {
       items.value( i+1,  ListBox.getText( i ) );
   }
   formBParams.parmItems( items );
   // Pass our object to FormB
   args.parmObject( formBParams );
   // Run FormB
   args.name( formstr( FormB ) );
   formRun = classFactory.formRunClass( Args );
   formRun.init();
   formrun.run();
   formrun.wait();
   if( formrun.closedOk() )
   {
       answerFromFormB.text( args.parm() );
   }
   super();
} </xpp>'


The code of init method of FormB <xpp>

 public void init()
 {
   EmplTable       emplTableRecord;
   FormBParams     formBParams;
   Array           items;
   int             i;
   ;
   super();
   // Check for passed arguments
   if( element.args() )
   {
       // get string parameter
       strValue.text( element.args().parm() );
       // get enum parameter
       if( element.args().parmEnumType() == EnumNum( NoYes ) )
       {
           NoYesEnumValue.selection( element.args().parmEnum() );
       }
       // get object parameter
       if( element.args().parmObject() )
       {
           formBParams = element.args().parmObject();
           items       = formBParams.parmItems();
           for( i=1; i<=items.lastIndex(); i++ )
           {
               ListBox.add( items.value(i) );
           }
           someDate.dateValue( formBParams.parmSomeDate() );
           someTime.value( formBParams.parmSomeTime() );
       }
       // get record parameter
       if( element.args().record() && element.args().record().TableId == TableNum( EmplTable ) )
       {
           emplTableRecord =  element.args().record();
           emplName.text( emplTableRecord.Name );
       }
   }
} </xpp>

 The code of ok button click event of FromB <xpp> 

void clicked()
 {
   super();
   element.args().parm( strAnswer.text() );
   element.closeOk();
} </xpp>
The above code is cut out from a demo which you can

Vendor return / Return purchase order in AX 2012

Introduction
In this post, we will walk you through return purchase order/ Vendor return in AX 2012. Many times company want to return goods which they have received from vendor due to various reasons such as damaged product, Expired product, Wrong product etc.
In order to return goods to vendor, we create a return purchase order in AX 2012.
There are two ways to create Vendor return in AX 2012:
1. Create purchase order with negative quantity
It is useful when there is no reference to specific purchase order or Return merchandise authorization is not required. In other word, company can return any item to vendor without any negotiation or notification.
This process is same as normal purchase order process with negative quantity.
2. Create a return purchase order.
 Return order is created in reference to specific purchase order and it should be authorized by vendor i.e. vendor should provide RMA number which indicates the permit for return of goods to vendor.
Requirement
Purchase order should already be created and invoiced in order to create a return order for it.
Background
Let's assume that the inventory manager accidently found some items are damaged. He notifies the purchasing manager about the issue. Purchasing manager decides to return the damaged items to the vendor. Purchasing manager creates a return purchase order to facilitate return of goods to vendor.
Steps to create return purchase order
1. Go to Account payable --> Common --> Purchase orders --> All purchase orders.
2. Click on Purchase order button to create new purchase order.
3. Enter: 
   a. Vendor account number: It is the same vendor to whom we are returning goods.
   b. Purchase type:Select purchase type as "Returned order".
  c. RMA number:As soon as we select purchase type as returned order, we can see RMA number field appears in the form. Enter the RMA number received from the vendor which permits the return of goods to vendor. 
  d.Enter other details as per requirement.
4. Click ok to create purchase order.
       
5. Now we need to add lines in the order which we can do it manually or with the help of credit note.
Add lines through Credit note
6. Go to Purchase order form-->click on purchase order lines--> Click on credit note 
    or 
    Go to purchase order form-->go to purchase fast tab--> click on credit note.
7. Select the appropriate purchase orders and their lines. 
Note:We can select multiple purchase orders and their specific lines to get them in return purchase order. Purchase orders specific to vendor selected in the return purchase order can only be seen in credit note form.
8. Click ok to get the lines in return purchase order.
9.Here you can see line in the return purchase order with negative quantity.
Confirmation
10. Post the Return purchase order confirmation after verifying all the details.
'
Receipt list
11. Post the receipt list for the items in the return purchase order.
12.The status of the inventory transactions goes to Physical reserved i.e. items will get physically reserved in the warehouse to get it picked for return.
Picking
13.Unfortunately, it is impossible to create a picking task for a purchase order line (or for an output order that can be created for the purchase order line). So, we cannot use the Picking form (Inventory management > Common Forms > Picking routes). We assume that the Purchase Manager calls the Warehouse Worker and asks him to perform the picking task: pick the broken items from a specific location, transfer the broken items to the outbound location, and inform the Purchase Manager about the operation being completed. The Warehouse Worker receives this in an informal form from the Purchase Manager, because we can't create the picking instruction document in Microsoft Dynamics AX for the returned items. When the Warehouse Worker completes the picking task and informs the Purchase Manager, she or he does the following: in the lines area of the Purchase order form, click the Update line --> Pick button.







14. Click on Add picking list update button to get the items available for picking list update.
15. Click on Register all to update the picked item in the system.
.16.Once done,Issue status goes to "Picked".
17. We can see inventory transactions status is updated from "Reserved physical" to "Picked".
Product Receipt
18,We assume that the items are loaded to the truck and delivered to the vendor. When the items are delivered, the Purchase Manager posts, prints, and sends the Packing slip document for the vendor to sign. The Packing slip document is a guarantee that the vendor receives the broken items.
19. Go to purchase order --> Receive fast tab--> Click on product receipt.
20. Enter the product receipt number.
21.Click ok to post the product receipt which is then send for the vendor to sign. 
22. Once done, we can see inventory transactions status is updated from "Picked" to "Deducted" as the items are deducted from the warehouse.
Invoice
23.The Purchase Manager posts, prints, and sends the invoice document for the vendor to sign. This document confirms that the vendor must pay (return) some amount of money for the broken items.
24. Go to purchase order -->Invoice tab--> Click on Invoice button to post the invoice for the order.
25. Enter the invoice number and click on Post button to post the invoice for the order.
26. Once done, invoice will send to vendor for signature. It confirms that the vendor must pay for broken items.
27. Go to inventory--> Transactions-->The status is updated from "Deducted" to "Sold"

Note:The invoice document which is generated has the title "Credit note". To view the credit note report, go to purchase order form-->go to Invoice tab--> Click on invoice journal-->click on Preview/Print -->Click on original preview/Copy preview.
In this way, we can create a Vendor return / Return purchase order in AX 2012.

Tuesday, 8 December 2015


Creation and Release of product through X ++ code



static void ProductMastersReleasedProduct(Args _args)
{
    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;
    try
    {
        //ProductMaster
        ecoResProductMaster.clear();
        ecoResProductMaster.initValue();
        ecoResProductMaster.ProductType = EcoResProductType::Item;
        ecoResProductMaster.DisplayProductNumber = "S6Testing";
        ecoResProductMaster.SearchName = "S6Testing";
        ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
        if (ecoResProductMaster.validateWrite())
        {
            ecoResProductMaster.insert();
            ecoResProductIdentifier.clear();
            ecoResProductIdentifier.initValue();
            ecoResProductIdentifier.ProductNumber = "S6Testing";
            ecoResProductIdentifier.Product = ecoResProductMaster.RecId;
            ecoResProductIdentifier.insert();
            //Product dimension group
            ecoResProductDimensionGroupProduct.clear();
            ecoResProductDimensionGroupProduct.initValue();
            ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);
            ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName("Config").RecId;
            if (ecoResProductDimensionGroupProduct.validateWrite())
            {
                ecoResProductDimensionGroupProduct.insert();
            }
            //Storage dimension group
            ecoResStorageDimensionGroupProduct.clear();
            ecoResStorageDimensionGroupProduct.initValue();
            ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;
            ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("site").RecId;
            if (ecoResStorageDimensionGroupProduct.validateWrite())
            {
                ecoResStorageDimensionGroupProduct.insert();
            }
            //Tracking dimension group
            ecoResTrackingDimensionGroupProduct.clear();
            ecoResTrackingDimensionGroupProduct.initValue();
            ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;
            ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("Btch").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, "S6Testing", "S6Testing");
            //Configuration
            ecoResConfiguration = EcoResConfiguration::findByName("STest-1");
            if (!ecoResConfiguration)
            {
                ecoResConfiguration.clear();
                ecoResConfiguration.initValue();
                ecoResConfiguration.Name = "STest-1";
                ecoResConfiguration.insert();
            }
            //Configuration assigned to product master
            ecoResProductMasterConfiguration.clear();
            ecoResProductMasterConfiguration.initValue();
            ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
            //ecoResProductMasterConfiguration.Description = "STest-1";
            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("STest-1", "", ""));
            ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName + "STest-1"/*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, "STesting", "STesting");
            //Released product
            inventTable.clear();
            inventTable.initValue();
            inventTable.initFromEcoResProduct(ecoResProductMaster);
            inventTable.ItemId = "S001";
            inventTable.NameAlias = "STesting";
            //inventTable.editTMSInventEnabled(true,NoYes::Yes);
            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 = "Audio";
                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 = "STest-1";/*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("Done!");
}
http://dynamicsaxspaingermany.blogspot.in/2013/05/creating-product-master-with-variants.html

Monday, 7 December 2015

Creation,Confirm,Picking,Packing and Invoice of sales order through X++ code : 

Creation:

static void Sak_SalesOrderCreate(Args _args)
{
NumberSeq numberSeq;
SalesTable salesTable;
SalesLine salesLine;
InventDim   inventdim;
ttsBegin;
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
numberSeq.used();
salesTable.SalesId = numberSeq.num();
salesTable.initValue();
salesTable.CustAccount = 'US-007';
salesTable.CurrencyCode = 'INR';
salesTable.LanguageId = "en-us";
salesTable.CustGroup = '30';
salesTable.InvoiceAccount = 'US-007';
salesTable.initFromCustTable();
if (!salesTable.validateWrite())
{
throw Exception::Error;
}
salesTable.insert();
salesLine.SalesId = salesTable.SalesId;
salesLine.ItemId = 'D0002';
salesLine.InventDimId = inventdim.inventDimId;
InventDim.InventLocationId = '11';
inventdim.InventSiteId = '1';
salesLine.createLine(true, true, true, true, true, true);
ttsCommit;
info(strFmt("Sales order '%1' has been created", salesTable.SalesId));
}
  

Confirmation : 


static void Sak_confirmSalesOrder (Args _args)
{
        SalesTable salesTable;
        SalesFormLetter salesFormLetter ;
        SalesTable = SalesTable::find('001011');
        salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
        salesFormLetter.update(salesTable);
        info(strFmt(" sales order Confirm '%1' has been ", salesTable.SalesId));

}

 

Picking :

 

static void Sak_SalesOrder_UpdatePickingList(Args _args)
{
    SalesFormLetter_PickingList salesFormLetter;
    SalesTable      salesTable = salesTable::find('001011');
    salesFormLetter = SalesFormLetter_PickingList::newPickingList();
    salesFormLetter.transDate(systemDateGet());
    salesFormLetter.update(salesTable,
                            systemdateget(),
                            SalesUpdate::All,
                            AccountOrder::None,
                            NoYes::No,
                            NoYes::No);
}

 

Packing:

 

static void Sak_postSalesPackingslip(Args _args)
{
SalesTable salesTable = SalesTable::find('001011');
SalesFormLetter salesFormLetter;

salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);
}

 

Invoice:

 

static void Sak_postSalesInvoice(Args _args)
{
// Define a class variable according to the  type of posting being performed
SalesFormLetter_Invoice invoice;
SalesTable salesTable;
// Select the salesTable to update
salesTable = SalesTable::find('001011');
// Create a new object of the SalesFormLetter_Invoice by using the construct-method in //SalesFormLetter
invoice = SalesFormLetter::construct(DocumentStatus::Invoice);
// Post the invoice of SO
invoice.update(salesTable, SystemDateGet(), SalesUpdate::All,AccountOrder::None, false, true);
// Set to true to print the invoice
}




Read from an Excel through X++ code




static void readExcelFiles(Args _args)

{

    SysExcelApplication         application;

    SysExcelWorkbooks           workbooks;

    SysExcelWorkbook            workbook;

    SysExcelWorksheets          worksheets;

    SysExcelWorksheet           worksheet;

    SysExcelCells               cells;

    Filename                    filename;

    COMVariantType              type;

    int                         rowNo;



    rowNo   = 2;//If the excel file having header.

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    filename = @"C:\Users\eswar.t\Desktop\item.xlsx";//Excel file path.

    try

    {

        workbooks.open(filename);

    }

    catch (Exception::Error)

    {

        throw error("File cannot be opened.");

    }

    workbook = workbooks.item(1);

    worksheets = workbook.worksheets();

    worksheet = worksheets.itemFromNum(1);//which shows excel sheet number.

    cells = worksheet.cells();



    type = cells.item(rowNo, 1).value().variantType();

    while (type != COMVariantType::VT_EMPTY)//loop through given excel column.

    {

        type = cells.item(rowNo+1, 1).value().variantType();//It will find variant type of column from given Excel sheet(ReadIntegerFile.xlsx) tiil it get empty.

        info(strFmt("%1",real2int(cells.item(rowNo,1).value().double())));

        rowNo++;//To get next column number in the loop.

    }

    application.quit();

}

Thursday, 3 December 2015

colours in grid

Here my scenario is I want to highlight the records in grid if the customer group of the particular record is 30.
  • Inorder to achieve that I have created a form with CustTable as datasource for that form .
  • In design node i have created a grid with fields CustGroup, Currency, Salesgroup and AccountNum. 
  •  Now I have overridden the displayoption method() in form datasource methods.

         public void displayOption(CustTable _CustTable, FormRowDisplayOption _options)
        {
         int myColor=WinApi::RGB2int(50,255,50);
         ;

        //if(_CustTable.CreditMax <= 100100)
        if(_CustTable.CustGroup == "30")
        _options.backColor(myColor);

        super(_CustTable, _options);
         //CustTable_ds.research();
         }
      The final form shoulde be