Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Friday, July 5, 2013

Controller class in Dynamic AX

Hi,

This controller class is used to print the reports directly instead of passing via param dialog.

class CustController extends SrsReportRunController
{
    #define.ReportName('CustReport.PrecisionDesign1')
    SRSRDPCustTableContractClass sRSRDPCustTableContractClass;
    CustTable custTable ;
 }

/************************************************************************/
public static CustController construct(Args _args)
{
    CustController controller=new CustController();
    controller.parmArgs(_args);
    return controller;
}

/**********************************************************************/
public static void main(Args _args)
{
    CustController controller = new CustController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(false);
    controller.startOperation();
 }
/****************************************************/
public boolean showQueryValues(str parameterName)
{
    return true;
}
/*****************************************************/
public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(CustTable) :
                CustTable = _args.record();
                break;
        }
    }
    qbds = _query.dataSourceTable(tableNum(CustTable));
    qbds.clearRanges();
    qbr = qbds.findRange(fieldName2id(tableNum(CustTable),fieldStr(CustTable, AccountNum)));
    if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(CustTable, AccountNum));
    }
    if(CustTable)
    {
        qbr.value(CustTable.AccountNum);
    }
}

/**********************************************************/
protected void prePromptModifyContract()
{
      super();
}

________________________________________________________________
--------------------------------------------------------------------------------------
Another sample controller class..

Controller class:(al khaldi)
 class SIController extends SrsReportRunController
{
  #define.ReportName(‘SIRep.PrecisionDesign1′)
    SIContract SIContract;
    CustInvoiceJour CustInvoiceJour ;
}

 protected void prePromptModifyContract()
{
   /* if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(CustInvoiceTrans))
    {
        CustInvoiceTrans = this.parmArgs().record();
    }
    if (!SIContract)
    {
        SIContract = this.parmReportContract().parmRdpContract();
    }
    SIContract.parmProjectId(projTable.ProjId);
   */
    super();
}

public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(CustInvoiceJour) :
                CustInvoiceJour = _args.record();
                break;
        }
    }

    qbds = _query.dataSourceTable(tableNum(CustInvoiceJour));

    qbds.clearRanges();

    qbr = qbds.findRange(fieldName2id(tableNum(CustInvoiceJour),fieldStr(CustInvoiceJour, SalesId)));

    if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(CustInvoiceJour, SalesId));
    }
    if(CustInvoiceJour)
    {
        qbr.value(CustInvoiceJour.SalesId);
    }

}

public boolean showQueryValues(str parameterName)
{
    return true;
}
 public static SIController construct(Args _args)
{
    SIController controller=new SIController();
    controller.parmArgs(_args);
    return controller;
}

public static void main(Args _args)
{
    SIController controller = new SIController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(false);
    controller.startOperation();
 }


Bhanu’s controller class:
Controller :
If  you create Controller class, then you need to create output menu item, set  property Object type – class, Object – Controller class created,  Linked permission type – SSRS report, Linked Permission object – SSRS report Created,  Linked permission object type – Design name.
class ProjHourUtilisationController extends SrsReportRunController
{
  #define.ReportName(‘ProjHourUtilisation.PrecisionDesign1′)
    ProjHourUtilisationContract projHourUtilisationContract;
    ProjTable projTable ;
}


protected void prePromptModifyContract()
{
    if (this.parmArgs()             &&
        this.parmArgs().record()    &&
        this.parmArgs().dataset() == tableNum(ProjTable))
    {
        projTable = this.parmArgs().record();
    }
    if (!projHourUtilisationContract)
    {
        projHourUtilisationContract = this.parmReportContract().parmRdpContract();
    }
    projHourUtilisationContract.parmProjectId(projTable.ProjId);
    super();
}

public void setRange(Args _args, Query _query)
{
    QueryBuildDataSource qbds;
    QueryBuildRange qbr;
    if (_args && _args.dataset())
    {
        switch(_args.dataset())
        {
            case tableNum(ProjTable) :
                projTable = _args.record();
                break;
        }
    }
     qbds = _query.dataSourceTable(tableNum(ProjTable));
     qbds.clearRanges();
     //qbr = qbds.findRange(fieldName2id(tableNum(ProjTable),fieldStr(ProjTable, ProjId)));
     if (!qbr)
    {
        qbr = qbds.addRange(fieldNum(ProjTable, ProjId));
    }
    if(ProjTable)
    {
        qbr.value(projTable.ProjId);
    }

}
public boolean showQueryValues(str parameterName)
{
    return true;}
 public static ProjHourUtilisationController construct(Args _args)
{
    ProjHourUtilisationController controller=new ProjHourUtilisationController();
    controller.parmArgs(_args);
    return controller;
}
public static void main(Args _args)
{
    ProjHourUtilisationController controller = new ProjHourUtilisationController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.setRange(_args, controller.parmReportContract().parmQueryContracts().lookup(controller.getFirstQueryContractKey()));
    controller.parmShowDialog(true);
    controller.startOperation();
}

Thursday, July 4, 2013

Select multiple selected values (records) from lookups in Dynamics AX

Hi,

Today i m gonna discuss a concept that will often used in many situations.Somtimes there comes a situation in which we want to select multiple rows from lookups that is, we want to display multiple selected values based on the selection of rows from lookups. So this behaviour can easily be achieved using SysLookMultiSelectCtrl class.

Steps to follow:

Create a Query named StudentCourse that contains 2 darasources say, Student & Course.
The figure below shows the structure of the two tables. Here Course field in Student table acts as a foreign key.


The below figure shows the StudentCourse Query used.
 

Use only those field that you want to show on the form or lookup.

Now create a new form named MultiSelectLookupCtrl and add a StringEdit control named as TestCtrl in the design node.Set its AutoDeclaration property to "Yes" so that we can access this control from X++ code.
 


Now override the following methods and write the following code.

In the ClassDeclaration of the form write the below code.

public class FormRun extends ObjectRun
{
    SysLookupMultiSelectCtrl msCtrl;
}

Override the init method of the form and place the below code

public void init()
{
    super();
    // TestCtrl - Name of control on which you want a lookup.
   // StudentCourse - Query to get the lookup data
    msCtrl = SysLookupMultiSelectCtrl::construct(element, TestCtrl, querystr(StudentCourse));
}


That's it, Now let's see how the selected rows are returned from the lookup.




On clicking the Ok button all the selected values are returned in the String control. 





To get the values and RecId of the selected rows, simply override the modified method of the TestCtrl and add the below code.

public boolean modified()
{
    boolean ret;

    container c,v;
    int i;
    ret = super(); 
    if (ret)
    {
        c = msCtrl.get();  // get RecIds of the selected rows
        v = msCtrl.getSelectedFieldValues(); // get actual value of the selected rows

        for (i = 1; i <= conLen(c);i++)
        {
            info(conPeek(c,i));
            info(conPeek(v,i));
        }
    }

    return ret;
}

SQL code to upate one Legal entity banner to all the legal entity in D365

 Hi, update companyimage set  companyimage.Image  = companyimageA.Image  from  ( select Image from companyimage where dataAreaid = 'USF...