Wednesday 11 December 2013

AX 2012 R2 with CU7- compilation

If the AX version is R2 with CU7, then don’t waste your time for compilation around 6 hours.

Use the following steps to have the compilation with 30 to 1 hour based on the system speed. Use the Command prompt to run the compilation.
There is new AXBuild.exe tool available from MS in the server folder. Path is
[Drive:]\Program Files\Microsoft Dynamics AX\60\Server\<YOUR AOS NAME>\bin

Use the path in CMD using cd command. And run the following command.

axbuild.exe xppcompileall /aos=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin" /workers=4               

where  
/aos = 01 is number of the AOS available in the server. AOS number will be identified in the AX Server configuration utility. It will be like 01,02,etc..
/worker = 4, give based on the server processor core. Count the number of code in the processor in Device Manager and give the number after “/worker =”.

You can the compilation output in the folder C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\Log\ as a HTML file.
You can import it in AX output window in Dev environment and resolve the errors.


Hope it will save your time.

Friday 29 November 2013

workflow approval validation:

u have to write this code in validate method of approval class(outcomes-approve(menuitem class))

this code is for when u submitted the workflow when approveing its check the rfq is created or not
if its created workflow approved other wise it gives error message as please create rfq for this order

public static boolean validate(Common _common, Args _args)
{
    PurchReqLine                purchReqLine,PurchReqLineloc;
    PurchReqTable               purchReqTable,purchReqTableLoc;
    Workflowtrackingstatustable workflowtrackingstatustable;
    Workflowtrackingtable       workflowtrackingtable;
    PurchRFQParameters             PurchParameters;
    HcmEmployment               hcmEmployment;
    purchRFQCaseTable           PurchRFQCaseTable;
    HcmWorker                   hcmWorker;
    DirPersonUser               dirPersonUser;

    str                         a,b,approvername;
    int                         emergencyAmount,totAmount;
    boolean c=true;
    boolean                     ret = true;

    boolean checkIfLinesFullyDistributed()
    {
        switch (_args.menuItemName())
        {
            case webActionItemStr (EPPurchReqApprovalApprove) :
            case menuitemActionStr(PurchReqApprovalApprove)   :
            case webActionItemStr (EPPurchReqTaskComplete)    :
            case menuitemActionStr(PurchReqTaskComplete)      :
                return true;
            default :
                return false;
        }
    }



select PurchParameters;
    {
if(PurchParameters.RestrictRFQ == NoYes::No)
{

   if (_common.TableId == tableNum(PurchReqTable))
    {
        purchReqTable = PurchReqTable::find(_common.RecId);
        //Call checkBudget to show any budget errors
           purchReqTable.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
            ret = ret && purchReqTable.isLinesFullyDistributed();
        }
        else
        {
            PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
        }


    }
    else
    {
        purchReqLine  = PurchReqLine::find(_common.RecId);
        purchReqTable = PurchReqTable::find(purchReqLine.PurchReqTable);
        SourceDocumentLineProcessor::submitSourceDocumentLineImplementation(purchReqLine, false, SourceDocumentLineAccountingStatus::FullyDistributed);

        //Call checkBudget to show any budget errors
        purchReqLine.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && purchReqLine.isFullyDistributed();
        }
    }

    if (ret  )
    {
       PurchReqTable::throwIfRFQPending(_common.TableId == tableNum(PurchReqTable), _common.RecId);
    }

}



if(PurchParameters.RestrictRFQ == NoYes::Yes)//select PurchParameters where PurchParameters.RestrictRFQ == 1;
{

    if (_common.TableId == tableNum(PurchReqTable))
    {
        purchReqTable = PurchReqTable::find(_common.RecId);
        while select count(RecId) from PurchReqLineloc where PurchReqLineloc.PurchReqTable == purchReqTable.RecId
                                        //&& PurchReqLineloc.SCO_RFQCaseId !=""
        {
            //a = PurchReqLineloc.RecId;
            //info(strfmt("a = %1",a));

        }
        while select PurchReqLineloc where PurchReqLineloc.PurchReqTable == purchReqTable.RecId
                                        && PurchReqLineloc.SCO_RFQCaseId !=""
        {
            //b = b+1;

        }
        //info(strfmt("b = %1",b));

        if(a == b)
        {
            //info(strfmt("a =%1 b=%2 ",a,b));

            //Call checkBudget to show any budget errors
           purchReqTable.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
            ret = ret && purchReqTable.isLinesFullyDistributed();
        }
        else
        {
            PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
        }


        }
        else
        {
            c= false;
            Box::stop(" RFQ have not  created for the line items ");
            return false;
        }
       // select PurchParameters where PurchParameters.RestrictRFQ == NoYes::No;
       // {


       // }



    }
    else
    {
        purchReqLine  = PurchReqLine::find(_common.RecId);
        purchReqTable = PurchReqTable::find(purchReqLine.PurchReqTable);
        SourceDocumentLineProcessor::submitSourceDocumentLineImplementation(purchReqLine, false, SourceDocumentLineAccountingStatus::FullyDistributed);

        //Call checkBudget to show any budget errors
        purchReqLine.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && purchReqLine.isFullyDistributed();
        }
    }


    if (ret  )
    {
       PurchReqTable::throwIfRFQPending(_common.TableId == tableNum(PurchReqTable), _common.RecId);
    }

}


    }
    return ret;
}

Lookup with range

Lookup with range:


public void lookup()
{
     QueryBuildDataSource    queryBuildDataSource;
    SysTableLookup          lookup;
    QueryBuildRange         queryBuildRange;
    Query                   query;

    query = new Query();

    // Add the first data source to the query
    queryBuildDataSource = query.addDataSource(tableNum(DNGRSBuildingBlocks));

    // Add the range to this first data source
    queryBuildRange = queryBuildDataSource.addRange(fieldNum(DNGRSBuildingBlocks, BuildingId));

    // Set the range
    queryBuildRange.value(netfloor.BuildingId);

    lookup = SysTableLookup::newParameters(tableNum(DNGRSBuildingBlocks), this, true);
    lookup.parmQuery(query);

    // Add the fields to be shown in the lookup form.
    lookup.addLookupfield(fieldNum(DNGRSBuildingBlocks, BlockID));
    //lookup.addLookupfield(fieldNum(JournalizingDefinition, JournalizingDefinitionDesc));
    //lookup.addLookupfield(fieldNum(JournalizingDefinition, JournalizingDefinitionModuleValue));

    // Perform the lookup.
    lookup.performFormLookup();
}


Monday 25 November 2013

adding image through resource

Upload image:

Use resource files in Axapta
In Application Object Tree, you can find resources node

Select resources node and right click; select Create from File, specify the file location for the new resource 

file. After that you can use this resource file in Axapta without specifying an absolute file path in your 

local/server system.

First, pick up the resource node from AOT;


SysResource::getResourceNode(); 

Then generate a temporary file for this resource file;

SysResource::saveToTempFile() 

Finally specify the temporary file path for controls. 

Here comes an example to show how to use a resource file as a background image of  a given form. 

{
ResourceNode            resourceNode;
FilePath  imagename;
;
resourceNode = SysResource::getResourceNode(resourcestr(ResourceName));
if (resourceNode)
{
resourceNode. AOTload();
imagename =  SysResource::saveToTempFile(resourceNode);
}
else
{
throw Error(“No file exists.”)

element.design().imageName(imagename); 
}

Example:

You can try "Resources" node to achieve your requirement.
Just Add a new resources under "Resources" node in AOT, than use following X++ code to access that image..
SysResource::getResourceNodeData(SysResource::getResourceNode('theaxapta_File'));



Create slaesline without item id:


Create slaesline without item id:
I am sure that there is a work around for this because when i am commenting the itemId and the salescategory the error will be : Item or category must be specified.

but when i want to add a salesaline with only sales categroy it will give me that "item ID must be specified". However ItemId can be nullable because on the AX Client i can create a salesline without an item.


As discussed in a parallel thread, sales lines without item IDs are supported from GUI, but there is an explicit validation in AxdSalesOrder.checkSalesLine():
if (!_axSalesLine.salesLine().RecId && !axSalesLine.parmItemId)
{
    error("@SYS300755"); // Item ID must be specified.
}

Comment this 4 lines of codes however i am still unable to create this salesorder then do this :

Ensure yourself that your changes have been compiled to CIL - if they're in X++ only, services won't see them.
If it doesn't help, then use the debugger to see what exactly is happening. Open Application Explorer in Visual Studio, add a breakpoint somewhere (e.g. toInfo.add()), attach the debugger to the AOS process and execute the service call.



Monday 11 November 2013

listpage enabling override methods(How to write methods on the list page Form in Ax 2012)

for enabling default override methods in list page we will set on property to group as

display target-- client(defautly it is auto we can change as client)




Scenario: I have a menu item that calls some class to do manipulation on the list page Form and I need to refresh the list page now. List pages do not allow writing of code on the Form, as they used interaction class.
Solution: You can write the code on list page buttons by setting DisplayTarget property to “Client” from auto. However after this change, you won’t be able to sue this button on the EP, so if you are thinking of using the same list page on the EP and planning to use the same button there, then do not do it. However f your domain is only the Form then you are good to do this.
Any ways override the clicked method and call research() of the data source to do this

Thursday 7 November 2013

how to getting the show button in info box while posting journal......

how to getting  the show button in info box while posting journal......
if we click on that show button its go to that current journal record..

When the general journal posted info box opened
Here we click on show button its go to current journal record.
For this functionality we can follow this procedure
Create one int64 field in ledgerjournal table(ex: TransferRefRecId)
And give the relation in ledgerjournal table to what ever table ur using that table(ex:I used the InventTransferTable)
(Then I am giving the relation as ledgerjournaltable. TransferRefRecId == InventTransferTable.recid)
After that where the journal posting method u write this following code
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer( LedgerJournalTable));


example:

in my form I wrote the journal posting method in form methods as


//[SysEntryPointAttribute(true)]
public void createGeneralJournalAndPost(Amount _shipnow)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTransCredit,journalTransDebit;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable,ledgerJournalTableUpdate;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    LedgerJournalTable      ledgerjournalTableDelete;
    LedgerJournalTrans      journalTransDelete;
    SalesParameters         SalesParameters;//JournalNameId;
    DimAttributeCustTable   DimAttributeCustTable;
    DimensionAttributeValueCombination valueCombination;
    CustInvoiceTable        custInvoiceTable;
    LedgerParameters        LedgerParameters;
    System.Exception        ex;
    str                     errorStr;
    LedgerJournalId         journalId;
    LedgerJournalPost       LedgerJournalPost;
    InventParameters        InventParameters;
    Amount                  markvalue;
    InventTransferTable InventTransferTable1;
    str s;

           markvalue = InventTransferTable.markupvalue(_shipnow);

            journalTable = new AxLedgerJournalTable();
            journalTransCredit = new AxLedgerJournalTrans();

              InventParameters = InventParameters::find();
            journalTable.parmJournalName(InventParameters.JournalNameId);
           // journalTable.parmTransferRecId(InventTransferTable.RecId);
            journalTable.parmDefaultDimension(InventTransferTable.DefaultDimension);
            journalTable.save();

            ledgerJournalTable = journalTable.ledgerJournalTable();

            ttsBegin;
            select forUpdate ledgerJournalTableUpdate  where ledgerJournalTableUpdate.JournalNum == ledgerJournalTable.JournalNum;
            ledgerJournalTableUpdate.TransferRefRecId = InventTransferTable.RecId;
            ledgerJournalTableUpdate.update();
            ttsCommit;
            journalTransCredit.parmJournalNum(ledgerJournalTable.JournalNum);

            journalTransCredit.parmTransDate(systemDateGet());
            journalTransCredit.parmAmountCurCredit(round(markvalue,2));
            journalTransCredit.parmAccountType(LedgerJournalACType::Ledger);
            journalTransCredit.parmLedgerDimension(InventParameters.RevenueDimension);
            journalTransCredit.parmDefaultDimension(InventTransferTable.DefaultDimension);
            LedgerParameters = LedgerParameters::find();
            journalTransCredit.parmOffsetLedgerDimension(InventParameters.LedgerDimension);

            journalTransCredit.save();

            ledgerJournalCheckPost              = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,Noyes::Yes);
            ledgerJournalCheckPost.run();
            //if (this.showInfo())
            //info(strFmt("%1,%2-%3",journalTable.parmJournalNum(),journalTransCredit.parmVoucher(),SysInfoAction_TableField::newBuffer(LedgerJournalTable)));
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer(LedgerJournalTable));
//////////////////this above line I wrote for showing show button
    }

//}

post the ledger journal through x++ code in AX 2012


For posting general journal we can use this table and classes
1.  LedgerJournalTable
2.  LedgerJournalTrans     
3.  ledgerJournalCheckPost(class) 



mandatory fields are offset account,ledger account,amount,journal name,journal number… etc


createFreeTextInvoicesAndPost(default class where one method is there-“ createGeneralJournalAndPost ”-through this method we can post the ledger journal through code)



[SysEntryPointAttribute(true)]
public str createGeneralJournalAndPost(Amount         _amount,
                                        CustAccount _cutomer,
                                        str         _businessUnit,
                                        ItemId      _itemId,
                                        str         _batchId,
                                        str         _qty,
                                        str         _costPrice,
                                        str         _billCode,
                                        str         _department,
                                        str         _costCenter,
                                        str         _employee,
                                        str         _NEW_OR_CANCEL_IND,
                                        str         _company,
                                        RecId       _InvTableRecId,
                                        LedgerDimensionDefaultAccount _defaultAccount)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTransCredit,journalTransDebit;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable,ledgerJournalTableUpdate;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    LedgerJournalTable      ledgerjournalTableDelete;
    LedgerJournalTrans      journalTransDelete;
    SalesParameters         SalesParameters;//JournalNameId;
    DimAttributeCustTable   DimAttributeCustTable;
    DimensionAttributeValueCombination valueCombination;
    CustInvoiceTable        custInvoiceTable;
    CustParameters  CustParameters;
    System.Exception        ex;
    str                     errorStr;
    LedgerJournalId         journalId;
    LedgerJournalPost       LedgerJournalPost;
    Args args = new Args();
    ;
    changeCompany(_company)
    {
        try
        {
            SalesParameters = SalesParameters::find();
            journalTable = new AxLedgerJournalTable();
            journalTransCredit = new AxLedgerJournalTrans();


            journalTable.parmJournalName(SalesParameters.JournalNameId);
            //journalTable.parmDefaultDimension(this.retDefaultDimension(_businessUnit,_department,_costCenter,_employee));
            journalTable.save();

            ledgerJournalTable = journalTable.ledgerJournalTable();

            select valueCombination where valueCombination.DisplayValue == _cutomer
                                       && valueCombination.LedgerDimensionType == LedgerDimensionType::Account
                                       && !valueCombination.MainAccount
                                       && !valueCombination.AccountStructure;

            journalTransCredit.parmJournalNum(ledgerJournalTable.JournalNum);
            journalTransCredit.parmTransDate(systemDateGet());
            journalTransCredit.parmAmountCurCredit(_amount);
            journalTransCredit.parmAccountType(LedgerJournalACType::Cust);
            journalTransCredit.parmLedgerDimension(valueCombination.RecId);
            journalTransCredit.parmDefaultDimension(_defaultAccount);
            CustParameters = CustParameters::find();

            if(_NEW_OR_CANCEL_IND == "C")
            {
                journalTransCredit.parmPostingProfile(CustParameters.PrepaymentPostingProfile);
            }
            else if(_NEW_OR_CANCEL_IND == "N")
            {
                journalTransCredit.parmPostingProfile(CustParameters.PostingProfile);
            }
            journalTransCredit.save();


            journalTransDebit = new AxLedgerJournalTrans();

            journalTransDebit.parmJournalNum(ledgerJournalTable.JournalNum);
            journalTransDebit.parmTransDate(systemDateGet());
            journalTransDebit.parmAmountCurDebit(_amount);
            journalTransDebit.parmAccountType(LedgerJournalACType::Cust);
            journalTransDebit.parmLedgerDimension(valueCombination.RecId);
            journalTransDebit.parmDefaultDimension(_defaultAccount);
            if(_NEW_OR_CANCEL_IND == "C")
            {
                journalTransDebit.parmPostingProfile(CustParameters.PostingProfile);
            }
            else if(_NEW_OR_CANCEL_IND == "N")
            {
                journalTransDebit.parmPostingProfile(CustParameters.PrepaymentPostingProfile);
            }
            journalTransDebit.save();

            ledgerJournalCheckPost              = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,Noyes::Yes);
            ledgerJournalCheckPost.run();

            return journalTransDebit.parmVoucher() + "," + journalTable.parmJournalNum();
        }
        catch(Exception::CLRError)
        {

            ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
            errorStr = "Error while Posting the General Journal Entry.";// + ex.ToString();
            delete_from journalTransDelete where journalTransDelete.JournalNum == journalId;
            delete_from ledgerjournalTableDelete where ledgerjournalTableDelete.JournalNum == journalId;
            //this.updateErrorInventMovement(sqlConGlobal,kRODBCParameters,itemIdStr,wareHouseStr,batchIdStr,businessUnitStr,costPriceStr,errorStr);
            this.insertErrorLogDetails(errorStr,_businessUnit,_itemId,_batchId,_qty,_costPrice,_billCode,_company);
            return "";
        }
    }


}





my code:


example:

in my form I wrote the journal posting method in form methods as


//[SysEntryPointAttribute(true)]
public void createGeneralJournalAndPost(Amount _shipnow)
{
    AxLedgerJournalTable    journalTable;
    AxLedgerJournalTrans    journalTransCredit,journalTransDebit;
    container               acctPattern;
    container               offSetAcctPattern;
    LedgerJournalTable      ledgerJournalTable,ledgerJournalTableUpdate;
    ledgerJournalCheckPost  ledgerJournalCheckPost;
    LedgerJournalTable      ledgerjournalTableDelete;
    LedgerJournalTrans      journalTransDelete;
    SalesParameters         SalesParameters;//JournalNameId;
    DimAttributeCustTable   DimAttributeCustTable;
    DimensionAttributeValueCombination valueCombination;
    CustInvoiceTable        custInvoiceTable;
    LedgerParameters        LedgerParameters;
    System.Exception        ex;
    str                     errorStr;
    LedgerJournalId         journalId;
    LedgerJournalPost       LedgerJournalPost;
    InventParameters        InventParameters;
    Amount                  markvalue;
    InventTransferTable InventTransferTable1;
    str s;

           markvalue = InventTransferTable.markupvalue(_shipnow);

            journalTable = new AxLedgerJournalTable();
            journalTransCredit = new AxLedgerJournalTrans();

              InventParameters = InventParameters::find();
            journalTable.parmJournalName(InventParameters.JournalNameId);
           // journalTable.parmTransferRecId(InventTransferTable.RecId);
            journalTable.parmDefaultDimension(InventTransferTable.DefaultDimension);
            journalTable.save();

            ledgerJournalTable = journalTable.ledgerJournalTable();

            ttsBegin;
            select forUpdate ledgerJournalTableUpdate  where ledgerJournalTableUpdate.JournalNum == ledgerJournalTable.JournalNum;
            ledgerJournalTableUpdate.TransferRefRecId = InventTransferTable.RecId;
            ledgerJournalTableUpdate.update();
            ttsCommit;
            journalTransCredit.parmJournalNum(ledgerJournalTable.JournalNum);

            journalTransCredit.parmTransDate(systemDateGet());
            journalTransCredit.parmAmountCurCredit(round(markvalue,2));
            journalTransCredit.parmAccountType(LedgerJournalACType::Ledger);
            journalTransCredit.parmLedgerDimension(InventParameters.RevenueDimension);
            journalTransCredit.parmDefaultDimension(InventTransferTable.DefaultDimension);
            LedgerParameters = LedgerParameters::find();
            journalTransCredit.parmOffsetLedgerDimension(InventParameters.LedgerDimension);

            journalTransCredit.save();

            ledgerJournalCheckPost              = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,Noyes::Yes);
            ledgerJournalCheckPost.run();
            //if (this.showInfo())
            //info(strFmt("%1,%2-%3",journalTable.parmJournalNum(),journalTransCredit.parmVoucher(),SysInfoAction_TableField::newBuffer(LedgerJournalTable)));
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer(LedgerJournalTable));
//////////////////this above line I wrote for showing show button
    }
//}




When the general journal posted info box opened
Here we click on show button its go to current journal record.
For this functionality we can follow this procedure
Create one int64 field in ledgerjournal table(ex: TransferRefRecId)
And give the relation in ledgerjournal table to what ever table ur using that table(ex:I used the InventTransferTable)
(Then I am giving the relation as ledgerjournaltable. TransferRefRecId == InventTransferTable.recid)
After that where the journal posting method u write this following code
info(strfmt("%1", journalTable.parmJournalNum()),'',SysInfoAction_TableField::newBuffer( LedgerJournalTable));