Quantcast
Channel: AX Developer Forum
Viewing all articles
Browse latest Browse all 9880

Inventory Transactions are not reflected for a Purchline created through code in ax 2012

$
0
0

I am working on a particular customization for my client, where i need to add supplementary items to every main item created in the Purch line. The client does not want to to use the Std Suppl itemCreate Classes & its functionality. Therefore  I added two extra field in the Purch line ( 1. Supplementary Item, & 2. Its qty). Then on click of a button I am creating a new record in the datasource level and entering the desired values. After this all the Purchase order related functions are working properly. But the supplementary item for which I created a record through code, there is no Inventory Transaction, It is not getting enabled even for the registration process. For your Reference I giving the code what i have written at the button click method.

void clicked()
{

    int             updatereccount = 0, newreccount = 0 , containersize;
    PurchLine                      buffer,updatebuffer, purchline3, newrecbuffer;
    ItemId          _itemid;
    boolean          ret = true;
     super();

    if (ret == true)
    {

            ttsBegin;

            glbbuffer = conNull();
            buffer = Purchline_ds.getFirst(1);
            while(buffer.RecId  != 0)
            {
               if((buffer.SupplementaryItemId != "") && (buffer.SuppItemQty >= 1) && (buffer.SupplUnit != ""))
                {
                   glbbuffer += buffer.SupplementaryItemId;       //1
                   glbbuffer += buffer.SupplUnit;       //2
                   glbbuffer += buffer.SuppItemPrice;       //3
                   glbbuffer += buffer.SuppItemQty;      //4
                   glbbuffer += buffer.RecId;               //5
                }
               buffer = Purchline_ds.getNext();
            }
            containersize = conLen(glbbuffer);
            while(containersize != 0)
            {
                  _itemid = conPeek(glbbuffer,1);

                 select forUpdate updatebuffer where updatebuffer.PurchId == Purchline.PurchId
                                           &&     updatebuffer.ItemId == _itemid
                                           && updatebuffer.PurchItemType == PurchItemType::Suppitem;
                    if(updatebuffer.RecId)
                    {
                        updatebuffer.PurchQty = conPeek(glbbuffer,4);
                        updatebuffer.PurchPrice = conPeek(glbbuffer,3);
                        updatebuffer.PurchUnit = conPeek(glbbuffer,2);
                        updatebuffer.ParentItem =conPeek(glbbuffer,5);
                        updatebuffer.update();
                        Purchline_ds.reread();
                        Purchline_ds.refresh();
                        updatereccount++;

                    }
                    else
                    {

                        Purchline_ds.create();

                        PurchLine.ItemId = conPeek(glbbuffer,1);
                        PurchLine.PurchUnit = conPeek(glbbuffer,2);
                        PurchLine.purchprice = conPeek(glbbuffer,3);
                        PurchLine.PurchQty = conPeek(glbbuffer,4);
                        PurchLine.ParentItem = conPeek(glbbuffer,5);
                        PurchLine.PurchItemType = PurchItemType::Suppitem;
                        PurchLine.PurchaseType = PurchaseType::Purch;
                        PurchLine.PurchStatus = PurchStatus::Backorder;
                        PurchLine.ProcurementCategory = EcoResCategory::find(EcoResProductCategory::findByItemIdCategoryHierarchyRole(PurchLine.ItemId,EcoResCategoryNamedHierarchyRole::Procurement).Category).RecId; // bharath as on 27/06/2013*/
                        //element.insertInventtransOrigin();
                       //  element.CreateInventtransPostingVoucher();
                       // element.insertInventtrans();

                         Purchline_ds.reread();
                        Purchline_ds.refresh();
                        newreccount++;
                     }
                     glbbuffer = conDel(glbbuffer,1,5);
                     containersize = conLen(glbbuffer);
             }
           // buffer = Purchline_ds.getNext();

            ttsCommit;


        Purchline_ds.reread();
        PurchLine_ds.executeQuery();
        Purchline_ds.refresh();
        Purchline_ds.research();
        Box::info(strFmt("For %1 Purchase Order %2 Records updated & %3 Records created",buffer.PurchId,updatereccount,newreccount),"Purchase Order");
    }

}

 

Please tell how to resolve this issue.

 

Thanks & regards

Bharat V


Viewing all articles
Browse latest Browse all 9880

Trending Articles