26 May 2014

Days between two dates not counting Saturday and Sunday:


// Days between two dates not counting Saturday and Sunday:

static void WorkDayDiff(Args _args)
{
    int i;
    Days workDayDiff(date d1, date d2)
    {
        Days y1 = dayofwk(d1);          // Day of week 1
        Days y2 = dayofwk(d2);          // Day of week 2
        date t1 = d1 - y1;              // Sunday before d1
        date t2 = d2 - y2;              // Sunday before d2
        Days y3 = (t2 - t1) div 7 * 5;  // Work days between Sundays
        Days y4 = min(y1-1,5);          // Work days before d1
        Days y5 = min(y2,5);            // Work days after t2
        return y3 - y4 + y5 - 1;        // Work days between d1 and d2
    }
    ;
    setprefix(strFmt("Today %1 %2", today(), dayname(dayofwk(today()))));
    for (i = -10; i <= 10; i++)
        info(strFmt("Diff %1 %2 = %3", today()+i, dayname(dayofwk(today()+i)), int2str(workDayDiff(today(), today() + i))));
}

How to access tables of different companies



//how to access tables of different companies
(crosscompany)?


static void crossCompanysupport(Args _args)
{
    container conCompanies = [ 'cee', 'ceu' ];
custTable custTable;
while select crossCompany : conCompanies custTable
    where custTable.accountNum >= "2000" && custTable.AccountNum <="5000"
{
print custTable.accountNum;
}
pause;

}

SSRS report using DP ,Contract, Controller


// SSRS report using DP ,Contract, Controller
//DP class

[
    SRSReportParameterAttribute(classstr

(PurchContractClass))
]
public class PurchDPClass extends

SRSReportDataProviderBase
{
    PurchTmp    purchTmp;
}


Method :

[SRSReportDataSetAttribute('PurchTmp')]
public purchTmp getpurchTmp()
{
    select * from purchTmp;
    return purchTmp;
}

Method  1:
[SysEntryPointAttribute(false)]
public void processReport()
{
    PurchTable  purchTable;
    PurchLine   purchLine;
    PurchContractClass purchContractClass;
    PurchId     purchId;
    PurchStatus purchStatus;
    InclTax     inclTax;

    purchContractClass = this.parmDataContract() as

PurchContractClass;
    purchId = purchContractClass.parmPurchId();
    //purchStatus = purchContractClass.parmPurchStatus();
    //inclTax = purchContractClass.parmInclTax();

     while select purchTable where purchTable.PurchId ==

purchId
    {
        purchTmp.PurchId = purchTable.PurchId;
        purchTmp.InvoiceAccount =

purchTable.InvoiceAccount;
        purchTmp.PurchName = purchTable.PurchName;
        purchTmp.InclTax = purchTable.InclTax;
        purchTmp.PaymMode = purchTable.PaymMode;
        purchTmp.PurchStatus = purchTable.PurchStatus;
        purchTmp.CurrencyCode =

purchTable.CurrencyCode;
     
        select purchId from purchLine where

purchLine.PurchId == purchTable.PurchId;
     
        purchTmp.itemid = purchLine.ItemId;
        purchTmp.VendGroup = purchLine.VendGroup;
        purchTmp.LineNumber = purchLine.LineNumber;
        purchTmp.PurchQty = purchLine.PurchQty;
     
        purchTmp.insert();
    }
}

//Contract Class:

[DataContractAttribute]
public class PurchContractClass
{
    PurchId     purchId;
    PurchStatus purchStatus;
    InclTax     inclTax;
}

Method 1:
[DataMemberAttribute("PurchId")]
public PurchId parmPurchId(PurchId _purchId = purchId)
{
    purchId = _purchId;
    return purchId;
}

Method 2:
[DataMemberAttribute("InclTax")]
public InclTax parmInclTax(InclTax _inclTax = inclTax)
{
    inclTax = _inclTax;
    return inclTax;
}

Method 3:

[DataMemberAttribute("PurchStatus")]
public PurchStatus parmPurchStatus(PurchStatus

_purchStatus = purchStatus)
{
    purchStatus = _purchStatus;
    return purchStatus;
}


// Controller Class

class PurchControllerClass extends

SrsReportRunController
{
     RecordSortedList       journalList;


     PurchView      purchview;
     //CWBProjInvoiceContract CWBProjInvoicecontract;
}

protected void initArgs(Args _args)
{
    args = new Args();

     if (_args.object() &&
        _args.object() is RecordSortedList)
    {
        journalList = _args.object();
    }
    else if (_args.record())
    {
        journalList = new RecordSortedList(tableNum

(PurchView));
        journalList.ins(_args.record());
    }

    journalList.first(purchview);

    this.parmReportName

("PurchReport.PurchReportDesign");
    this.parmShowDialog(false);

    this.parmArgs(_args);
}

protected void preRunModifyContract()
{
    PurchContractClass contract;
    contract = this.parmReportContract

().parmRdpContract() as PurchContractClass;

    contract.parmPurchId(purchview.PurchId);
    contract.parmVendAccount(purchview.InvoiceAccount);
    ////contract.parmPurchStatus(purchview.PurchStatus);
    //contract.parm(purchview.PurchId);
}

public static void main(Args _args)
{
   PurchControllerClass controller = new

PurchControllerClass();
    ;


   controller.parmReportName

("PurchReport.PurchReportDesign");
   //controller.parmArgs(_args);
    controller.initArgs(_argsssssss);

    controller.startOperation();
}

Calculation of Explosive Qty

Calculation of Explosive Qty

// Calculation of Explosive Qty

private void CalculationOfExplosiveQty()
{
    ExplosiveQty    netExplosiveQty;
    InventTable     _InventTable;
    InventSum       _InventSum;
    InventLocation  _InventLocation;
    PurchParmLine   _PurchParmLine,_PurchParmLine1;
    InventDim       _InventDim,_InventDim1;
    real            totalQty,PhysicalQty;
    PurchId         _PurchId;
    ;

    while select _InventDim1 group by InventLocationId join _PurchParmLine1 where _PurchParmLine1.ParmId == PurchParmTable.ParmId
                                                                                && _InventDim1.inventDimId == _PurchParmLine1.InventDimId
    {
        totalQty =0;
        info(strFmt("%1",_InventDim1.InventLocationId));

        while select _PurchParmLine join _InventDim group by InventLocationId where _PurchParmLine.ParmId == PurchParmTable.ParmId
                                                                            && _InventDim.inventDimId == _PurchParmLine.InventDimid
                                                                            && _InventDim.inventlocationid == _InventDim1.inventlocationid

        {
            _PurchId = PurchParmLine.OrigPurchId;
            select _InventTable where _InventTable.ItemId == _PurchParmLine.ItemId;
            netExplosiveQty = _InventTable.ExplosiveQty;
            select _InventLocation where _InventLocation.InventLocationId == _InventDim.InventLocationId;
            totalQty += PurchParmLine.ReceiveNow * netExplosiveQty;
        }
            PhysicalQty = 0;
            while select _InventSum join _InventDim join _InventTable where _InventSum.InventDimId == _InventDim.inventDimId
                                                                        && _InventDim.InventLocationId == _InventDim1.InventLocationId
                                                                        && _InventTable.ItemId == _InventSum.ItemId
            {
                PhysicalQty += _InventSum.PhysicalInvent * ((_InventTable.ExplosiveQty == 0)? 1 : _InventTable.ExplosiveQty) ;
                // info(strFmt("%1 :  %2",_InventSum.PhysicalInvent,_InventDim.InventLocationId));
            }
                // info(strFmt("%1 : %2",PhysicalQty,totalQty));
                if(_InventLocation.ExplosiveLimit < totalQty + PhysicalQty)
                {
                    info(strFmt("Limit Exceed in  wearhouse %1",_InventDim1.InventLocationId));
                }
                else
                {
                    info("Purchase Order Posted");
                }
    }
}

To open Form by X++



// To open Form by X++

static void OpenForm()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(VendTable));
args.record(CustTable::find("XYZ"));

formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}

Query Examples


// Query Examples


static void Query (Args _args)
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
SalesTable SalesTable;
query = new Query();

qbds = query.addDataSource(TableNum (SalesTable));

qbr = qbds.addRange(FieldNum (SalesTable,CustAccount));


qbr.value ('3003');

qbds.addSortField (FieldNum(SalesTable,SalesId));

queryRun = new QueryRun(query);


while (queryRun.next())
{

SalesTable = queryRun.get(tableNum(SalesTable));
print SalesTable.SalesId;

}
pause;
}



this.query().dataSourceTable(tablenum(SupplProduct)).addRange(fieldnum(SupplProduct, ShowOnReport)).value(QueryValue(NoYesCombo::Yes));

this.query().dataSourceTable(tablenum(AppointmentTable)).addRange(fieldnum(AppointmentTable, AppointmentId)).value(queryValue(activeAppoint.AppointmentId));
//
InventoryMangementOnhandView is ViewDatasource

 qbr = InventoryMangementOnhandView_ds.query().dataSourceNo(1).addRange(fieldNum(InventoryMangementOnhandView, DatePhysical));
    _qbr = InventoryMangementOnhandView_ds.query().dataSourceNo(1).addRange(fieldNum(InventoryMangementOnhandView, StatusReceipt));

//TO filter a date value to view data source

    qbr.value(strFmt("<%1", AsonDate.dateValue()));
// To filter a two enum value to view filtered date value to view datasource

    _qbr.value("1..2");

// Example range Value

 query = new Query();
        queryBuildDataSource = query.addDataSource(
            TableNum(CustTable));

        //----------- Range: AccountNum
        queryBuildRange = queryBuildDataSource.addRange(
            FieldNum(CustTable,AccountNum));
        queryBuildRange.value("4000..5000");


// Example with Explanation :
http://nathalie.gimenez.free.fr/DynamicsAX/DynamicsProg_queryrange.html

WorkFlow LifeCycle


WorkFlow LifeCycle

RDP TUtorial

OLAP Vs OLTP

22 May 2014

To modified a particular field in table for update and refresh by Automatically if thr any change occur in X++

TO modified particular field in table through X++ by Automatically if thr any change occur


Form -> Grid->Field -> method overwritee ( modified)

and below code to update

public boolean modified()
{
    boolean ret;

    ret = super();

    QualityInspectionTable_DS.research();
    QualityInspectionTable_DS.refresh();

    QualityInspectionLine_DS.research();
    QualityInspectionLine_DS.refresh();

    return ret;
}

update table

update table

To update a field value in Table and ill sum the value in one field to update in another table.

Code in table level by Update method( where u want to change record  and update status)

public void update()
{
     QualityInspectionLine   _QualityInspectionLine;
     QualityInspectionTable  _QualityInspectionTable;

     super();

     select sum(percent) from _QualityInspectionLine where _QualityInspectionLine.ProjectID == this.ProjectID
                                                    && _QualityInspectionLine.InspectionStatus == InspectionStatus::Completed;

     select forUpdate _QualityInspectionTable where _QualityInspectionTable.ProjectID == this.ProjectID;

     ttsBegin;

     _QualityInspectionTable.TotalProgress = _QualityInspectionLine.percent;
     _QualityInspectionTable.doUpdate();

     ttsCommit;

}

To Filter a record by dialog field thorugh X++ method clicked

// To Filter a record by dialog field thorugh X++ method clicked


// Date field

void MethodName()
{
    EmployeeDetails Emp_1;
    EmployeeTMP EmpTmp;

    Dialog dialog;
    DialogGroup dialogGroup;

    DialogField dialogFieldDateOfJoining1;
    DialogField dialogFieldDateOfJoining2;

    dialog = new Dialog("Employee DateOfJoining Filter");
    dialogGroup = dialog.addGroup("Employee Date Of Joining");
    dialogFieldDateOfJoining1 = dialog.addField(extendedTypeStr(DateofJoining),"Date Of Joining > = :");
    dialogFieldDateOfJoining2 = dialog.addField(extendedTypeStr(DateofJoining),"Date Of Joining < = :");

    delete_from EmpTmp;
    if(dialog.run())
    {

        //delete_from EmpTmp;

        while select Emp_1  where Emp_1.DateofJoining >= dialogFieldDateOfJoining1.value() && Emp_1.DateofJoining <= dialogFieldDateOfJoining2.value()
        {

            EmpTmp.EmpCode = Emp_1.EmpCode;
            EmpTmp.EmpName = Emp_1.EmpName;
            EmpTmp.EmployeeDesgination = Emp_1.EmployeeDesgination;
            EmpTmp.Age = Emp_1.Age;
            EmpTmp.DateOfBirth = Emp_1.DateOfBirth;
            EmpTmp.DateofJoining = Emp_1.DateofJoining;
            EmpTmp.DateOfTermination =Emp_1.DateOfTermination;
            EmpTmp.Salary = Emp_1.Salary;
            EmpTmp.CurrencyValue = Emp_1.CurrencyValue;
            EmpTmp.TypeOfJob = Emp_1.TypeOfJob;
            EmpTmp.YearsOfExperience = Emp_1.YearsOfExperience;

            EmpTmp.insert();


        }
       EmployeeTMP_ds.research();
       EmployeeTMP_ds.refresh();
    }

  //  element.close();
    element.detach();
}


// Int field

void method name()
{
    EmployeeDetails Emp_1;
   EmployeeTMP EmpTmp;

    Dialog dialog;
    DialogGroup dialogGroup;

    DialogField dialogFieldEmpCode1;
    DialogField dialogFieldEmpCode2;

    dialog = new Dialog("Employee Code Filter");
    dialogGroup = dialog.addGroup("Employee Code");
    dialogFieldEmpCode1 = dialog.addField(extendedTypeStr(EmpCode),"EmpCode > :");
    dialogFieldEmpCode2 = dialog.addField(extendedTypeStr(EmpCode),"EmpCode < :");

    delete_from EmpTmp;

    if(dialog.run())
    {
        //info(dialogFieldEmpCode1.value());
        //info(dialogFieldEmpCode2.value());
       // delete_from EmpTmp;

        while select Emp_1  where Emp_1.EmpCode > dialogFieldEmpCode1.value()   && Emp_1.EmpCode < dialogFieldEmpCode2.value()
        {
            EmpTmp.EmpCode = Emp_1.EmpCode;
            EmpTmp.EmpName = Emp_1.EmpName;
            EmpTmp.EmployeeDesgination = Emp_1.EmployeeDesgination;
            EmpTmp.Age = Emp_1.Age;
            EmpTmp.DateOfBirth = Emp_1.DateOfBirth;
            EmpTmp.DateofJoining = Emp_1.DateofJoining;
            EmpTmp.DateOfTermination =Emp_1.DateOfTermination;
            EmpTmp.Salary = Emp_1.Salary;
            EmpTmp.CurrencyValue = Emp_1.CurrencyValue;
            EmpTmp.TypeOfJob = Emp_1.TypeOfJob;
            EmpTmp.YearsOfExperience = Emp_1.YearsOfExperience;

            EmpTmp.insert();


        }
       EmployeeTMP_ds.research();
       EmployeeTMP_ds.refresh();
    }
  //  element.close();
    element.detach();
}


// Enum Field

void method Name()
{
    EmployeeDetails Emp_1;
   EmployeeTMP EmpTmp;

    Dialog dialog;
    DialogGroup dialogGroup;

    DialogField dialogFieldEmployeeDesgination;

    dialog = new Dialog("Employee Designation Filter");
    dialogGroup = dialog.addGroup(" Employee Designation");
    dialogFieldEmployeeDesgination = dialog.addField(enumStr(EmployeeDesgination),"EmployeeDesgination :");

    delete_from EmpTmp;

    if(dialog.run())
    {
        //delete_from EmpTmp;

        while select Emp_1  where Emp_1.EmployeeDesgination ==dialogFieldEmployeeDesgination.value()
        {

            EmpTmp.EmpCode = Emp_1.EmpCode;
            EmpTmp.EmpName = Emp_1.EmpName;
            EmpTmp.EmployeeDesgination = Emp_1.EmployeeDesgination;
            EmpTmp.Age = Emp_1.Age;
            EmpTmp.DateOfBirth = Emp_1.DateOfBirth;
            EmpTmp.DateofJoining = Emp_1.DateofJoining;
            EmpTmp.DateOfTermination =Emp_1.DateOfTermination;
            EmpTmp.Salary = Emp_1.Salary;
            EmpTmp.CurrencyValue = Emp_1.CurrencyValue;
            EmpTmp.TypeOfJob = Emp_1.TypeOfJob;
            EmpTmp.YearsOfExperience = Emp_1.YearsOfExperience;

            EmpTmp.insert();


        }
       EmployeeTMP_ds.research();
       EmployeeTMP_ds.refresh();
    }

  //  element.close();
    element.detach();
}

Backup Excel data to table through X++

Backup Excel data to table through X++


Void clicked()
{
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    COMVariantType type;
    Name name;
    FileName filename;

    EmployeeBackup employeeBackup;
    Args          args = new Args();
    int row;

    int empcode;
    str salary;
    str age;
    str YearsOfexperience;
    str empname;

    TypeOfJob jobtype;


    EmployeeDesgination employeedesgination;
    employeedesgination tmpDesgination;

    CurrencyValue currencyValue;
    currencyValue tmpCurrency;

    date dateofbirth,dateofjoining,dateofreveling;
    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    //specify the file path that you want to read
    filename = "C:\\Test.xlsx";//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); //Here 1 is the worksheet Number
        cells = worksheet.cells();
            do

            {
                row++;

                empcode = any2int(cells.item(row,1).value().double());
                empname = cells.item(row,2).value().bstr();
                tmpDesgination = str2enum(employeedesgination,cells.item(row, 3).value().bStr());
                dateofjoining = any2date(cells.item(row,4).value().date());
                dateofreveling = any2date(cells.item(row,5).value().date());
                dateofbirth = any2date(cells.item(row,6).value().date());
                age = any2str(cells.item(row,7).value().toString());
                salary = any2str(cells.item(row,8).value().toString());
                tmpCurrency = str2enum(currencyValue,cells.item(row,9).value().bStr());
                jobtype = str2enum(jobtype,cells.item(row, 10).value().bStr());
                YearsOfexperience = any2str(cells.item(row,11).value().toString());



                 employeeBackup.EmpCode = empcode;
                 employeeBackup.EmpName = empname;
                 employeeBackup.EmployeeDesgination = tmpDesgination;
                 employeeBackup.DateofJoining = dateofjoining;
                 employeeBackup.DateOfTermination = dateofreveling;
                 employeeBackup.DateOfBirth = dateofbirth;
                 employeeBackup.Age = age;
                 employeeBackup.Salary = salary;
                 employeeBackup.CurrencyValue = tmpCurrency;
                 employeeBackup.TypeOfJob = jobtype;
                 employeeBackup.YearsOfExperience = YearsOfexperience;

                 employeeBackup.insert();

                type = cells.item(row+1, 1).value().variantType();
            }
                while (type != COMVariantType::VT_EMPTY);
                application.quit();
    super();
}

Creation of dialog and dialog field Example

Creation of dialog and dialog field Example


void method name()
{
            Dialog dialog;
            DialogGroup dialogGroup;
            DialogField dialogFieldCustAccount;
            DialogField dialogFieldCurrency;
            DialogField dialogFieldVendAccount;
            DialogField dialogFieldCustomerGroup;
            DialogField dialogFieldInclTax;
            dialog = new Dialog("Simple Dialog");
            dialogGroup = dialog.addGroup("Customer");
            dialogFieldCustAccount = dialog.addField(extendedTypeStr(CustAccount));
            dialogFieldCustomerGroup = dialog.addField(extendedTypeStr(CustGroupId));
            dialogGroup = dialog.addGroup("Currency");
            dialogFieldCurrency = dialog.addField(extendedTypeStr(CurrencyCode));
            dialogGroup = dialog.addGroup("Vendor Details");
            dialogFieldVendAccount = dialog.addField(extendedTypeStr(VendAccount));
            dialogGroup = dialog.addGroup("Tax Group");
            dialogFieldInclTax = dialog.addField(extendedTypeStr(InclTax));
            if(dialog.run())
            {
                info(dialogFieldCustAccount.value());
                info(dialogFieldCurrency.value());
                info(dialogFieldCustomerGroup.value());
                info(dialogFieldVendAccount.value());
                info(dialogFieldIncltax.value());
            }

}

Calculation Of Explosive Qty, whether item Qty in warehouse is exceed or within in a limit

Calculation Of Explosive Qty, whether item Qty in warehouse is exceed or within in a limit

// Calculation Of Explosive Qty, whether item Qty in warehouse is exceed or within in a limit - - For purchase order -  purchpackingslipjournalpost (class) - create new method as Explosive qty and call this method in endpost method to purchpackingslipjournalpost

private void CalculationOfExplosiveQty()
{
    ExplosiveQty    netExplosiveQty;
    InventTable     _InventTable;
    InventSum       _InventSum;
    InventLocation  _InventLocation;
    PurchParmLine   _PurchParmLine,_PurchParmLine1;
    InventDim       _InventDim,_InventDim1;
    real            totalQty,PhysicalQty;
    PurchId         _PurchId;
    ;
 
    while select _InventDim1 group by InventLocationId join _PurchParmLine1 where _PurchParmLine1.ParmId == PurchParmTable.ParmId
                                                                                && _InventDim1.inventDimId == _PurchParmLine1.InventDimId
    {
        totalQty =0;
        info(strFmt("%1",_InventDim.InventLocationId));
     
        while select _PurchParmLine join _InventDim group by InventLocationId where _PurchParmLine.ParmId == PurchParmTable.ParmId
                                                                            && _InventDim.inventDimId == _PurchParmLine.InventDimid
                                                                            && _InventDim.inventlocationid == _InventDim1.inventlocationid
                                                                         
        {
            _PurchId = PurchParmLine.OrigPurchId;
            select _InventTable where _InventTable.ItemId == _PurchParmLine.ItemId;
            netExplosiveQty = _InventTable.ExplosiveQty;
            select _InventLocation where _InventLocation.InventLocationId == _InventDim.InventLocationId;
            totalQty += PurchParmLine.ReceiveNow * netExplosiveQty;
        }
            PhysicalQty = 0;
            while select _InventSum join _InventDim join _InventTable where _InventSum.InventDimId == _InventDim.inventDimId
                                                                        && _InventDim.InventLocationId == _InventDim1.InventLocationId
                                                                        && _InventTable.ItemId == _InventSum.ItemId
            {
                PhysicalQty += _InventSum.PhysicalInvent * ((_InventTable.ExplosiveQty == 0)? 1 : _InventTable.ExplosiveQty) ;
                // info(strFmt("%1 :  %2",_InventSum.PhysicalInvent,_InventDim.InventLocationId));
            }
                // info(strFmt("%1 : %2",PhysicalQty,totalQty));
                if(_InventLocation.ExplosiveLimit < totalQty + PhysicalQty)
                {
                    info(strFmt("Limit Exceed in  wearhouse %1",_InventDim1.InventLocationId));
                }
                else
                {
                    info("Purchase Order Posted");
                }
    }
}

About Dynamics AX

About Dynamics AX

Why Microsoft Dynamics AX?

Microsoft Dynamics AX core strengths are in manufacturing and distribution. More than 60% of Microsoft Dynamics AX users are from these industries.

Microsoft Dynamics AX allows you to share and update information across the company in real time, across multiple sites and in multiple countries. Microsoft Dynamics AX is an all-inclusive, company-wide ERP system that customizes to your business.

Microsoft Dynamics AX is completely integrated from your platform up through the end-user business solutions applications.

Microsoft Dynamics AX works like and with familiar Microsoft software, automating and streamlining business processes and connecting you with global customers, business partners and subsidiaries in a way that helps you drive business success.

Microsoft Dynamics AX has fully integrated financials, eliminating the need for duplicate data entry in other areas of the business. Microsoft Dynamics AX provides greater insight into your finances and improves your ability to make the right decisions quickly.

Microsoft Dynamics AX is an object oriented ERP solution that has the lowest total cost of ownership in the market.

Microsoft Dynamics AX fits perfectly in the manufacturing industry with its multi-item dimensions capability, multi-storage capability, multi-language support and its open-source integrated development environment. 

Creation RDP and Contract Class

Creation RDP and Contract Class

DP CLASS

[SRSReportParameterAttribute(classstr

(SRSRDPCustTableContractClass))]
class SRSRDPClass extends SRSReportDataProviderBase
{
CustTemp custTemp;
}

[SRSReportDataSetAttribute("custTemp")]
public custTemp getcustTemp()
{
select * from custTemp;
return custTemp;
}

[SysEntryPointAttribute(false)]
public void processReport()
{
CustTable custTable;
SRSRDPCustTableContractClass

srsRDPCustTableContractClass;
AccountNum accountNum;

srsRDPCustTableContractClass = this.parmDataContract()

as srsRDPCustTableContractClass;
accountNum =

srsRDPCustTableContractClass.parmAccountNum();
  while select * from custTable where 

custTable.AccountNum ==  accountNum
{
custTemp.AccountNum = 

custTable.AccountNum;
custTemp.PriceGroup = 

custTable.PriceGroup;
custTemp.Currency = 

custTable.Currency;
custTemp.insert();
}
}
-----------------------------------------------------------------------

-------------------------------------------
CONTRACT CLASS

class SRSRDPCustTableContractClass
{
AccountNum accountNum;
}

[DataMemberAttribute("AccountNum")]
public AccountNum parmAccountNum(AccountNum

_accountNum = accountNum)
{
accountNum = _accountNum;
return accountNum;
}

Form to Form by CMD Button(Clicked)

Form to Form by CMD Button(Clicked)


void clicked()
{
    Args    args;
    FormRun formRun;
    ;
    args = new Args();
    args.name(formStr(FormDet));
    //args.caller(this);
    formRun = classFactory.formRunClass(args);
    formRun.init();
    formRun.run();
    formRun.detach();
 

    super();

}

20 May 2014

Running the report via code


Running the report via code


private void generateVendBalanceReport()
{
    SrsReportRunController      reportRunController;
    Map                         queryContracts;
    MapEnumerator               mapEnum;
    Query                       query;
    QueryBuildRange             range;

    SrsReportDataContract       contract;
    VendBalanceReportContract   rdpContract;
    FilePath                    outputPath = "c:\\";
    ;

    // Create the report run controller
    reportRunController = new SrsReportRunController();
    reportRunController.parmReportName('VendBalanceReport.AutoDesign1');
    reportRunController.parmLoadFromSysLastValue(false);

    // Set printer settings (print to file, format, filename, etc).
    contract    = reportRunController.parmReportContract();
    contract.parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    contract.parmPrintSettings().overwriteFile(true);
    contract.parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    contract.parmPrintSettings().fileName(outputPath + "VendBalanceReport.pdf");
 
    // Use our custom-defined report contract class
    rdpContract = contract.parmRdpContract() as VendBalanceReportContract;
    rdpContract.parmToDate(systemDateGet());
    rdpContract.parmIncludeVendorsWithoutTransactions(true);  
 
    // Add a range to the query (filter vendors that begin with '3').
    queryContracts = contract.parmQueryContracts();
    mapEnum = queryContracts.getEnumerator();
    while(mapEnum.moveNext())
    {
        // Get the query and update the datasource as required
        query = mapEnum.currentValue();
        range = SysQuery::findOrCreateRange(query.dataSourceTable(tableNum(VendTable)),fieldNum(VendTable,AccountNum));
        range.value('3*');
    }

    // Run the report
    reportRunController.runReport();
}

Save SSRS report to pdf that uses Controller classes [Dynamics AX 2012]


//  Save SSRS report to pdf that uses Controller classes [Dynamics AX 2012]

static void SR_SaveReportToPDFFromController(Args _args)
{
    SalesInvoiceController  salesInvoiceController;
    SalesInvoiceContract    salesInvoiceContract;
    Args                    args = new Args();
    SrsReportRunImpl        srsReportRun;
    CustInvoiceJour         custInvoiceJour;
    ReportName              reportName = "SalesInvoice.Report";
    ;

    select firstOnly custInvoiceJour;
    args.record(custInvoiceJour);
 
    salesInvoiceController = new SalesInvoiceController();
    salesInvoiceController.parmReportName(reportName);
 
    salesInvoiceContract = salesInvoiceController.parmReportContract().parmRdpContract();
    salesInvoiceContract.parmRecordId(custInvoiceJour.RecId); // Record id must be passed otherwise the report will be empty
    salesInvoiceContract.parmCountryRegionISOCode(SysCountryRegionCode::countryInfo()); // comment this code if tested in pre release
    salesInvoiceController.parmArgs(args);

    srsReportRun = salesInvoiceController.parmReportRun() as SrsReportRunImpl;
 
    salesInvoiceController.parmReportRun(srsReportRun);
    salesInvoiceController.parmReportContract().parmPrintSettings().printMediumType(SRSPrintMediumType::File);
    salesInvoiceController.parmReportContract().parmPrintSettings().overwriteFile(true);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileFormat(SRSReportFileFormat::PDF);
    salesInvoiceController.parmReportContract().parmPrintSettings().fileName(‘c:\\SR_SalesInvoice.pdf’);
    salesInvoiceController.runReport();
}

From Date to Todate filter


// From Date to TOdate filter
void clicked()
{
    SalesTablesReport salesTablesReport;
    TempSalesRep    tempSalesRepins;

    //delete_from tempSalesRepins;
//    info(strFmt("%1",fromdate.dateValue()));
    delete_from TempSalesRep;
     while select salesTablesReport where salesTablesReport.FromDate >= (fromdate.dateValue())
                                      && salesTablesReport.ToDate <=(todate.dateValue())
    {
        tempSalesRepins.CustAccount = salesTablesReport.CustAccount;
        tempSalesRepins.FromDate = salesTablesReport.FromDate;
        tempSalesRepins.ToDate = salesTablesReport.ToDate;
        tempSalesRepins.insert();
       // info(strFmt("%1",salesTablesReport.FromDate));
    }
    TempSalesRep_ds.research();
    TempSalesRep_ds.refresh();

}

Steps to create a Number sequence

steps: to create a Number sequence


1.  Create an edt : CarId .

     AOT >> Extended Data Types(String) >> New  >> Properties >> Name  >> Car Id.

2. Write a code on lode module() on NumberSeqModuleProject

{
     datatype.parmDatatypeId(extendedTypeNum(Car Id));
     datatype.parmReferenceHelp(literalStr("@SYS334483"));
     datatype.parmWizardIsManual(NoYes::No);
     datatype.parmWizardIsChangeDownAllowed(NoYes::No);
     datatype.parmWizardIsChangeUpAllowed(NoYes::No);
     datatype.parmWizardHighest(999999);
     datatype.parmSortField(20);
     datatype.addParameterType(NumberSeqParameterType::DataArea, true, false);
     this.create(datatype);
}

3.Write a method on Projparameters Table

     client server static NumberSequenceReference numRefcarId()
{
     return NumberSeqReference::findReference(extendedTypeNum(car Id));
}

4.Write a job and run that

static void Carid(Args _args)
{
    NumberSeqModuleProject  NumberSeqModuleProject = new NumberSeqModuleProject();
    ;
    NumberSeqModuleProject.load();
}


5. Then run the wizard

   Organization Administration >> CommonForms >> Numbersequences>>Numbersequences>> Generate >> run the wizard.

6.Now we have to check the number sequence  is correctly working  for that write a job:

static void number(Args _args)
{
    NumberSeq  numberSeq;
    CarId num;
    ;
    numberSeq = NumberSeq::newGetNum(ProjParameters::numRefcarId());
    num = numberSeq.num();
    info(num);
}

  Run the above job.We will find the generated Number     sequence.                                                    .

7. Now we want that Number Sequence in form level(Car Table):

Declare the number sequence On Form Declaration:

public class FormRun extends ObjectRun
{
    NumberSeqFormHandler numberSeqFormHandler;

}

 8. Write the NumberSeqFormHandler() in form methods node.

NumberSeqFormHandler numberSeqFormHandler()
{
    if (!numberSeqFormHandler)
    {
        numberSeqFormHandler = NumberSeqFormHandler::newForm(ProjParameters::numRefcarId      ().NumberSequenceId,
                                                             element,
                                                             CarTable_DS,
                                                             fieldNum(CarTable, Car Id)
                                                            );
    }
    return numberSeqFormHandler;
}


9.Write the close() on the form methods node.

void close()
{
    if (numberSeqFormHandler)
    {
        numberSeqFormHandler.formMethodClose();
    }
    super(); }

10. Then final add the below methods on data source methods node


Create()

void create(boolean append = false,
            boolean extern = false // If created externally
{
    element.numberSeqFormHandler().formMethodDataSourceCreatePre();

    super(append);

    if (!extern)
    {
        element.numberSeqFormHandler().formMethodDataSourceCreate(true);
    }
}

Delete()

public void delete()
{
    element.numberSeqFormHandler().formMethodDataSourceDelete();
    super();
}

Write()

public void write()
{
    super();
    element.numberSeqFormHandler().formMethodDataSourceWrite();
}

Validate Write()

public boolean validateWrite()
{
    boolean         ret;
    ret = super();
    ret = element.numberSeqFormHandler().formMethodDataSourceValidateWrite(ret) && ret;
    if (ret)
    {
        CarTable.validateWrite();
    }
    return ret;
}

Link Active()

public void linkActive()
{
    ;
    element.numberSeqFormHandler().formMethodDataSourceLinkActive();
    super();
}

 Now our numberseqence is generated .