Tuesday, 16 July 2013

AX help Codes

AX help Codes

Find Method()

static NSGOvertimeHeader find(OvertimereqId   _OvertimereqId,
                      boolean       _forUpdate = false)
{
    NSGOvertimeHeader nSGOvertimeHeader;
    ;
    if (_OvertimereqId)
    {
        if (_forUpdate)
            nSGOvertimeHeader.selectForUpdate(_forUpdate);

        select firstonly nSGOvertimeHeader
            index hint NSGReqNoIdx
            where nSGOvertimeHeader.Requestno == _OvertimereqId;
    }
    return nSGOvertimeHeader;
}


Display Method()
1.       1.      display DirPartyName emplname()
{
    DirPartyName empName;
    ;
    empName = HcmWorker::findByPersonnelNumber(this.EmpId).name();
    return empName;
}
1.       2.      display DirPartyName PositionName ()
{


    //return HcmJob::findByJob(EmplContract::findActiveContract(this.EmpId).CurrentPosition).description();

    returnHcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::findByPersonnelNumber(this.EmpID).RecId).description();
}

Exist Method()
static boolean exist(OvertimereqId _OvertimereqId)
{
    return _OvertimereqId && (select firstonly RecId from nSGOvertimeHeader
                                index hint NSGReqNoIdx
                                where nSGOvertimeHeader.Requestno  == _OvertimereqId).RecId !=0;
}


Form Splitter():
Form Method
Class Declaration
public class FormRun extends ObjectRun
{
    NumberSeqFormHandler            numberSeqFormHandler;
   SysFormSplitter_Y                _formSplitter;
}
public void init()
{
    ;
    super();
    _formSplitter = new SysFormSplitter_Y(VerticalSplitter,Header,element);
}
Design Group Tool
MouseDown:
int mouseDown(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseDown(x, y, button, ctrl, shift);
}
Mouse Up
int mouseUp(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseUp(x, y, button, ctrl, shift);
}
Mouse Move
int mouseMove(int x, int y, int button, boolean ctrl, boolean shift)
{
    int ret;

    ret = super(x, y, button, ctrl, shift);

    Return _formSplitter.mouseMove(x,y,button,ctrl,shift);
}
Number Sequence Methods:
Table -> Method
New Method:
static client server NumberSequenceReference numRefCustomerID()
{
    ;
    return NumberSeqReference::findReference(extendedTypeNum(TransNoVoun));
}
Form -> Methods
Class:
public class FormRun extends ObjectRun
{
    NumberSeqFormHandler numberSeqFormHandler;
   
}
New Method
NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
       numberSeqFormHandler = NumberSeqFormHandler::newForm(CustomerTransTable::numRefTransno().NumberSequenceId,
                                                             element,
                                                             CustomerTransTable_DS,
                                                             fieldNum(CustomerTransTable, TransactionNumber)
                                                            );
    }
    return numberSeqFormHandler;

}
Form -> Datasource -> Table -> Methods
Delete Method:
public void delete()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    element.numberSeqFormHandler1().formMethodDataSourceDelete();
    element.numberSeqFormHandler2().formMethodDataSourceDelete();
    super();

}
Create Method:
public void create(boolean _append = false)
{
    ;
    super(_append);
    element.numberSeqFormHandler().formMethodDataSourceCreate();
    element.numberSeqFormHandler1().formMethodDataSourceCreate();
    element.numberSeqFormHandler2().formMethodDataSourceCreate();
}
 Write Method:
public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
    element.numberSeqFormHandler1().formMethodDataSourceWrite();
    element.numberSeqFormHandler2().formMethodDataSourceWrite();
}
SSRS Report Code
Base Class – Class Declaration:

[
SRSReportQueryAttribute(queryStr(Thomas_Invoiced_SSRS)),
SRSReportParameterAttribute(classStr(InvoicedSales_BaseClassContract))
]
class InvoicedSales_BaseClass extends SRSReportDataProviderBase
{
    Invoiced_SSRS_Test_Temp  invoiced_SSRS_Test_Temp;
    QueryRun queryrun;
    FromDate          fromDate;
  ToDate            toDate;
}
Getting SSRS Report name:
[
SRSReportDataSetAttribute(tableStr(Invoiced_SSRS_Test_Temp))
]
public Invoiced_SSRS_Test_Temp getInvoiced_SSRS_Test_Temp()
{
    select * from invoiced_SSRS_Test_Temp;
    return invoiced_SSRS_Test_Temp;
}
Get Report parameter Value:
private void getReportParameters()
{
    InvoicedSales_BaseClassContract InvoicedSales_BaseClassContract = this.parmDataContract();
    if (InvoicedSales_BaseClassContract)
    {
        fromDate  = InvoicedSales_BaseClassContract.parmFromDate();
        toDate  = InvoicedSales_BaseClassContract.parmToDate();
    }
 }
Inserting Values into the Temp Table:

public void InsertintoTempTableDetails(SalesTable _SalesTable,SalesLine _SalesLine)
{
    invoiced_SSRS_Test_Temp.SalesId=_SalesTable.SalesId;
    invoiced_SSRS_Test_Temp.InvoiceAccount=_SalesTable.InvoiceAccount;
    invoiced_SSRS_Test_Temp.ItemId=_SalesLine.ItemId;
    invoiced_SSRS_Test_Temp.SalesQty=_SalesLine.SalesQty;
    invoiced_SSRS_Test_Temp.SalesPrice=_SalesLine.SalesPrice;
    invoiced_SSRS_Test_Temp.insert();
}
Report Processing:
[SysEntryPointAttribute(false)]
public void processReport()
{
    SalesTable salesTable;
    SalesLine salesline;
    ;
    this.getReportParameters();
    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),fromDate,toDate));
    while(queryRun.next())
    {
   if(queryrun.changed(tableNum(SalesTable))||queryrun.changed(tableNum(SalesLine)))
        {
        salesTable=queryrun.get(tableNum(SalesTable));
            salesline=queryrun.get(tableNum(SalesLine));
          this.InsertintoTempTableDetails(salesTable,salesline);
        }
    }
}
Build Query:
private Query buildQuery(
    Query                   _query,
    FromDate                _fromDate,
    ToDate                  _toDate
    )
    {

    if(_fromDate && _toDate)
        _query.dataSourceTable(tablenum(SalesTable),1).addRange(fieldnum(SalesTable, DeliveryDate)).value(queryRange(_fromDate,_toDate));

        return _query;
     }
Controller Class- Class Declaration:

class InvoiceSalesReportController extends SrsReportRunController
{

}
Construct Method:
public static InvoiceSalesReportController construct(Args _args)
{
    InvoiceSalesReportController controller=new InvoiceSalesReportController();
    controller.parmArgs(_args);
    return controller;
}
Main Method:
public static void main(Args _args)
{
    InvoiceSalesReportController controller=new InvoiceSalesReportController();
    controller.parmArgs(_args);
    InvoiceSalesReportController::construct(_args).startOperation();
}
Contract Class-Class Declaration:
public class InvoicedSales_BaseClassContract implements SysOperationValidatable
{
    FromDate fromDate;
    ToDate toDate;
    Mark_Status Mark_Statusloc;
}
Parameter Condition Methods:
[
    DataMemberAttribute('Status'),
    //SysOperationLabelAttribute(literalstr("@SYS5209")),
    //SysOperationHelpTextAttribute(literalstr("@SYS67")),
    //SysOperationGroupMemberAttribute('Date'),
    SysOperationDisplayOrderAttribute('3')
]
public Mark_Status parmMark_Status(Mark_Status _Mark_Status = Mark_Statusloc)
{
    Mark_Statusloc = _Mark_Status;
    return Mark_Statusloc;
}
Validate Method:
public boolean validate()
{
    boolean             isValid = true;

    if (!fromDate)
    {
        isValid = checkFailed(“From Date should be entered”);
    }
    if (!toDate)
    {
        isValid = checkFailed(“To Date should be entered”);
    }
    if (isValid && (fromDate > toDate))
    {
        isValid = checkFailed(strfmt(“From Date should be less than or equal to To Date”, date2StrUsr(fromDate, DateFlags::FormatAll), date2StrUsr(toDate, DateFlags::FormatAll)));
    }

    return isValid;
}

Bug fixing in vs 2010
Trying to use VS 2010 for DynamicsAx 2012 Reporting i get this error ” The Type Initializer for ‘Microsoft.Dynamics.BusinessConnector.Session.SessionCache’ threw an exception”.

I’ve just contact MS support on my problem, and they fixed it.
In your event viewer, do you have an error on Microsoft-Windows-LoadPerf at the same time you launche VS?
If it’s so, run as administrator in a command line: lodctr /r
It will rebuild your counter. It fixed my problem.


No comments:

Post a Comment