Friday, January 22, 2016

FUNCTIONS IN AX 2012

static void systemFunctions(Args _args)
{
    real r;
    str s ;
    int i;
    container c = ['DAT', 'USMF', 'IBM' ];
    CustTable custtable;
    Test    test;
    Gender  g;
    ;

    //s = dayName(4);
    s = curUserId();
    info(strFmt("current user id is %1",s));
    //i = sessionId();
    //info(strFmt("session id is %1", i));
    //s = funcName();
    //info(strFmt("current extension is %1", s));
    //info(strFmt("The fourth day of this week is %1",s));
    //g = Gender::Male;
    //info(enum2str(g));
    //i=dayofyr(today());
    //i = dayofyr(systemDateGet());
    //info(strFmt("%1", i));
    //info(subStr("jagadeesh", 4,2));
    //info(strUpr("jagadeesh"));
    //info(strRep("jagadeesh", 10));
    //info(strPoke("Jagadeesh", "Vemula",5));
    //info(strLwr("JAGADEESH"));
    //info(strLTrim(     "Jagadeesh"   ));
    //print strFind("Vemula", "V",1, 5);
    //pause;
    //info(strDel("Jagadeesh",5,5));
    //r = trunc(2.414);
    //info(strFmt("%1",r));
   //while select firstOnly10 reverse crossCompany : c * from custtable
    //{
    //info(custtable.AccountNum);
    //}
    //ttsBegin;
    //while select forUpdate test
        //where test.Name == "jagadeeshVemula"
    //{
        //test.Name = "jagadeesh"+"Vemula";
        //test.Update();
        //info(test.Name);
    //}
    //ttsCommit;
    //CustTrans custtrans;
    //;
    //while select firstOnly10 reverse AccountNum from custtable order by custgroup desc
       //// join CustTrans
       //// where custtable.AccountNum == custtrans.AccountNum
    //{
        //info(strFmt("%1,%2", custtable.AccountNum , custtable.CustGroup));
    //}

   // s = strRem("MynameIs","Is");
    //s = strltrim("ABCD - EFGH") ;
   // info(s);
    //s = curUserId();
    //s = curext();
    //r = corrFlagSet(0.36, 2);
    //info(strFmt("%1",corrFlagGet(r)));
    //c+= "item2";
    //c+= "item3";
    ////c = conNull();
    ////info(strFmt("%1",conLen(c)));
    //for(i=1; i<= conLen(c); i++)
    //{
        //info(strFmt("before %1",conPeek( c, i)));
    //}

    //c = conIns(c,2, "item1");//["item1", "item2"], 1);
    ////r= acos(0.0);
    ////s= strFmt("The arc cosine of 0.0is %1", r);
    ////info(s);
    ////c = conIns(c, 1, "item1");
    ////c = conIns(c, 2, "item2");
    //
    //for(i=1; i<= conLen(c); i++)
    //{
        //info(strFmt("after %1",conPeek( c, i)));
    //}
}

X++ CODE TO DO PARTIAL PRODUCT RECEIPT FOR PO

static void PO_partialpackingslip(Args  args)
{
   PurchFormLetter PurchFormLetter;
   PurchTable PurchTable;
   date _ReceivedDate = systemDateGet();
   PurchId _purchId = "000403";
   PurchLine purchLine;
   ;

   PurchTable = PurchTable::find(_purchId,true);
   ttsBegin;
   while select forUpdate * from purchLine
       where purchLine.PurchId == PurchTable.PurchId
   {
       purchLine.PurchReceivedNow = 5;
       purchLine.update();
   }
   ttsCommit;
   purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
   //Enum name is recorded, label is registered
   //change enum on purchUpdate to change what value(s) are posted
   PurchFormLetter.update(PurchTable,"test",systemDateGet(),     PurchUpdate::ReceiveNow,AccountOrder::None,NoYes::No,NoYes::No);
}

X++ CODE TO CREATE PURCHASE ORDER AND PO CONFIRMATION

static void OrderCreate(Args _args)
    {
        NumberSeq            numberSeq;
        PurchTable            purchTable;
        PurchLine            purchLine;
        purchFormLetter     purchFormLetter;
        ttsBegin;
        numberSeq             =    NumberSeq::newGetNum(PurchParameters::numRefPurchId());
        numberSeq.used();
        purchTable.PurchId    =    numberSeq.num();
        purchTable.initValue();

        // po creation
        purchTable.initFromVendTable(VendTable::find('1100'));
        if (!purchTable.validateWrite())
            {
                throw Exception::Error;
            }
        purchTable.insert();
        purchLine.PurchId    =    purchTable.PurchId;
        purchLine.ItemId     =    'D0006';
        purchLine.createLine(true, true, true, true, true, true);
        ttsCommit;
        info(strFmt("Purchase order '%1,%2' has been created", purchTable.PurchId,          purchTable.DeliveryDate));

        // po  confirmation
        purchformletter = purchformletter::construct(documentstatus::purchaseorder);
        purchformletter.update(purchtable, strfmt("inv_%1", purchtable.purchid));
        info(strFmt("purchase order '%1' has been confirmed", purchTable.DeliveryDate));
     
        // po  Invoice
        purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
        purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));
        info(strFmt(" Purchase order '%1' has been invoiced", purchtable.InvoiceAccount));
    }


  • Make sure that warehouse and site are specified for the given product in product information management->manage inventory->default order settings and site specific order settings.
  • If warehouse and site are not specified for the given item.
  • If not specified it will throw error as site and warehouse must be specified for the given item.

X++ CODE TO IMPORT VENDORS FROM EXCEL

static void importVendorCSV(Args _args)
    {
        CommaIO                     csvFile;
        container                   readCon;
        counter                     icount,inserted;
        Dialog                      dialog;
        DialogField                 dfFileName;
        DirPartyRecId               partyRecId,contactPartyRecid;
        Name                        name,contactName;
        VendTable                   vendtable;
        FileName                    fileName;
        ;
        #File  
        dialog = new Dialog("Pick the file");
        dfFileName = dialog.addField(extendedTypeStr(FileNameOpen));
        dialog.filenameLookupFilter(["All files",#AllFiles]);
        if (dialog.run())
        {
                filename =  dfFileName.value();
        }  
        csvFile = new CommaIO(filename, 'r');
        if (csvFile)
        {
            readCon = csvFile.read();
            while (csvFile.status() == IO_Status::OK)
            {
                icount++;
                if (readCon)
                {
                    vendtable.clear();
                    vendtable.initValue();
                    vendtable.Party = partyRecId;
                    vendtable.AccountNum = conPeek(readCon,1);
                    vendtable.VendGroup  = conPeek(readCon,2);
                    vendtable.Currency   = conPeek(readCon,3);
                    ttsBegin;
                    vendtable.insert();
                    ttsCommit;
                }
                //icount++;
              break;
            }
            inserted++;  
        }
         info(strfmt("%1 records inserted out of %2",inserted,icount));
    }

CODE TO DELETE RELEASED PRODUCT

                                   
  • The released product in product information management can be deleted through x++ code though it has been used in po and so.

        static void productdelete(Args _args)
{
InventTable inventTable;
delete_from inventTable where inventTable.ItemId == "fan";
//inventTable.delete();
info(strFmt("%1 item was deleted ", inventTable.ItemId));
}

REQUIREMENT ON MULTIPLE PO INVOICE THROUGH X++


  • Consider two purchase orders created using same vendor.
  • Till Product receipt the process should  be done functionally from front end.
  • Now both of them should be invoiced with same invoice id through x++ code.
  • Invoice should be done for only received quantity in two purchase orders.
To do multiple po's invoice for same vendor,  You to have to pass partial product receipt name as shown in below code .

static void invoicePurchaseOrder_Packingslip(Args _args)
{
Purchformletter_invoice Purchformletter;
Purchtable purchtable;
vendPackingSlipJour vendPackingSlipJour;
vendPackingSlipTrans vendPackingSlipTrans;
TmpFrmVirtual tmpFrmVirtual;
List selectedList = new List(Types::Record);
purchParmUpdate purchParmUpdate;
purchParmtable purchParmtable;
ParmId parmId;
VendInvoiceInfoTable vendinvoiceinfoTable;
;
try
{
ttsbegin;
tmpFrmVirtual.setTmp();
// Add the packing slips into tmpFrmVirtual
while select vendpackingslipjour
where vendpackingslipjour.packingslipid == ‘Packingslip1’ && vendpackingslipjour.packingslipid == 'packingslip2'
{
tmpFrmVirtual.clear();
tmpFrmVirtual.TableNum = vendpackingslipjour.TableId;
tmpFrmVirtual.RecordNo = vendpackingslipjour.RecId;
tmpFrmVirtual.NoYes = NoYes::Yes;
tmpFrmVirtual.Id = vendpackingslipjour.PurchId;
tmpFrmVirtual.insert();

}
while select tmpFrmVirtual
{
selectedList.addEnd(tmpFrmVirtual);
}
// Construct form letter
Purchformletter = purchformletter::construct(DocumentStatus::Invoice);
// Add the packing slips to the purch form letter
Purchformletter.selectFromJournal(selectedList.pack());

purchformletter.sumBy(AccountOrder::None);
purchformletter.reArrangeNow(true);
purchformletter.reArrange();
purchformletter.specQty(purchupdate::PackingSlip);
parmId = purchformletter.parmId();

// Execute
ttscommit;
purchformletter.startOperation();
if (purchFormLetter.parmJournalRecord().recid)
{
info(“Invoice completed sucessfully”);
}
}
catch
{
throw error(strFmt(“Invoice failed”));
}