Alfasith AX

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

Wednesday, July 17, 2013

UI Builder class in Dynamic AX

UI Builder class 

Today i will share how to give a filter lookup using an UI Builder class.                                                                                            

Step1 : First create a DP class for a customer report


[
    SRSReportQueryAttribute(queryStr(BSCustTable)),
    SRSReportParameterAttribute(classStr(SRCustomLookUpContract))

]
class SRCustomLookupDP extends SRSReportDataProviderBase
{
    SRCustomLookUpContract contract;
    CustNameTmp        CustNameTmp;
    AccountNum         AccountNum;
    CustGroupId       CustGroupId;

}

private Query buildQuery(
    Query                   _query,
    AccountNum                _AccountNum
    )
    {

    if(_AccountNum)
        _query.dataSourceTable(tablenum(CustTable), 1).addRange(fieldnum(CustTable, AccountNum)).value(queryvalue(_AccountNum));

        return _query;
     }

[
    SRSReportDataSetAttribute('CustNameTmp')
]
public CustNameTmp getCustNameTmp()
{
    select * from CustNameTmp;

    return CustNameTmp;
}

private void getReportParameters()
{
    SRCustomLookUpContract SRCustomLookUpContract = this.parmDataContract();

    if (SRCustomLookUpContract)
    {
        AccountNum    = SRCustomLookUpContract.parmAccountNum();
        CustGroupId  = SRCustomLookUpContract.parmCustGroup();
        //AccountNum    = SRCustomLookUpContract.parmAccountNum2();
    }
 }


public  void insertCustNameTmp(AccountNum _accountNum)
{
    CustTable  CustTable;

    ;
    while select CustTable where CustTable.AccountNum == _accountNum
    {
       CustNameTmp.AccountNum = _accountNum;
       CustNameTmp.Name     = CustTable.name();

       CustNameTmp.insert();
    }

}


/// <summary>
/// executes the logic based on the parameter entries
/// </summary>
/// <remarks>
/// fills up the temp table
/// </remarks>
[SysEntryPointAttribute]
public void processReport()
{
    Query query;
    QueryRun queryRun;
    CustTable       custTable;
    ;
    this.getReportParameters();
    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),AccountNum));
    while(queryRun.next())
    {
        custTable = queryRun.get(tableNum(custTable));
        this.insertCustNameTmp(custTable.AccountNum);
    }
}

Step2 : Second create a Contract class for a customer report


[DataContractAttribute,
SysOperationContractProcessingAttribute(classstr(SRCustomLookupsUIBuilder))
]
class SRCustomLookUpContract
{
    AccountNum        accountNum;
    CustGroupId      CustGroupId;

}


[DataMemberAttribute('AccountNum')
    ]
public AccountNum parmAccountNum(AccountNum _accountNum = accountNum)
{
    accountNum = _accountNum;
    return accountNum;
}


[DataMemberAttribute('CustGroup')
    ]
public CustGroupId parmCustGroup(CustGroupId _CustGroupId = CustGroupId)
{
    CustGroupId = _CustGroupId;
    return CustGroupId;
}


Step3 : Third create a UI Builder class for a customer report


class SRCustomLookupsUIBuilder extends SrsReportDataContractUIBuilder
{
      DialogField   dialogAccountNum,dialogCustGroup; //dialogCreditRating;
      DialogGroup   dialogGroup, dialogGroup2;
      boolean       enable;


}


private void accountNumLookup(FormStringControl accountNumLookup)
{
    Query                   query = new Query();
    QueryBuildDataSource    qbds_CustTable;
    SysTableLookup          sysTableLookup;
    QueryBuildRange         qbr;

    if (accountNumLookup != null)
    {
        // Create an instance of SysTableLookup with
        // the current calling form control.

        sysTableLookup = SysTableLookup::newParameters(tablenum(CustTable), accountNumLookup);
        //sysTableLookup.addLookupMethod(
        // Add fields to be shown in the lookup form.
        qbds_CustTable = query.addDataSource(tableNum(CustTable));
         sysTableLookup.addLookupfield(fieldnum(CustTable, CustGroup),true);
        sysTableLookup.addLookupfield(fieldnum(CustTable, AccountNum), false);

        qbr = qbds_CustTable.addRange(fieldNum(CustTable,CustGroup));
        qbr.value("");
        sysTableLookup.parmUseLookupValue(false);

        sysTableLookup.parmQuery(query);

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

    }
}


/// <summary>
///    Builds the dialog.
/// </summary>
/// <remarks>
///    The dialog appears with the parameters.
/// </remarks>

public void build()
{
    SRCustomLookUpContract rdpContract =  this.dataContractObject();

    dialogAccountNum = this.addDialogField(methodstr(SRCustomLookUpContract,parmAccountNum),rdpContract);
    dialogAccountNum.lookupButton(3);

    dialogCustGroup = this.addDialogField(methodstr(SRCustomLookUpContract,parmCustGroup),rdpContract);
    dialogAccountNum.lookupButton(2);
}


private void CustGroupLookup(FormStringControl CustGroupLookup)
{
    Query                   query = new Query();
    QueryBuildDataSource    qbds_CustTable;
    SysTableLookup          sysTableLook;
    QueryBuildRange         qbr;
    CustTable               CustTable;
    if (CustGroupLookup != null)
    {
        // Create an instance of SysTableLookup with
        // the current calling form control.

        sysTableLook = SysTableLookup::newParameters(tablenum(CustTable), CustGroupLookup);
        //sysTableLookup.addLookupMethod(
        // Add fields to be shown in the lookup form.
        qbds_CustTable = query.addDataSource(tableNum(CustTable));
        sysTableLook.addLookupfield(fieldnum(CustTable, CustGroup),false);
         sysTableLook.addLookupfield(fieldnum(CustTable, AccountNum), true);

        qbr = qbds_CustTable.addRange(fieldNum(CustTable,CustGroup));
        qbr.value(dialogAccountNum.value());
        sysTableLook.parmUseLookupValue(false);

        sysTableLook.parmQuery(query);

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

    }
}


public boolean customerAccModified(FormStringControl _control)
{
    dialogAccountNum.value(_control.valueStr());

    return true;
}


public void postRun()
{
    Dialog dialogLocal = this.dialog();
    DialogField dialogField, dialogField1;

    super();

    // This method should be called in order to handle events on dialogs.
    dialogLocal.dialogForm().formRun().controlMethodOverload(false);

    // Override the methods of department  field.

    dialogField1 = this.bindInfo().getDialogField(this.dataContractObject(), methodstr(SRCustomLookUpContract, parmCustGroup));
    dialogField1.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(SRCustomLookupsUIBuilder,CustGroupLookup), this);

    dialogField = this.bindInfo().getDialogField(this.dataContractObject(), methodstr(SRCustomLookUpContract, parmAccountNum));
    dialogField.registerOverrideMethod(methodstr(FormStringControl, lookup), methodstr(SRCustomLookupsUIBuilder,accountNumLookup), this);

}

RDP Class in Dynamic AX

Style 1.

[
SRSReportQueryAttribute (querystr(CustTableQry)),
SRSReportParameterAttribute(classstr(CustContractClass))
]
class CustTableRDP extends SRSReportDataProviderBase
{
CustTableTmp custTableTmp;
}
*********************************
[
SysEntryPointAttribute(false)
]
public void processReport()
{
QueryRun             queryRun;
Query                query;
CustTable            custTable;
CustContractClass    CustContractClass;
AccountNum           accountNum;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange     queryBuildRange;
query = this.parmQuery();
   
CustContractClass = this.parmDataContract() as CustContractClass;
accountNum = CustContractClass.parmAccountNum();
// Add parameters to the query.
queryBuildDataSource = query.dataSourceTable(tablenum(CustTable));
if(accountNum)
{
queryBuildRange = queryBuildDataSource.findRange(fieldnum(CustTable, AccountNum));
if (!queryBuildRange)
{
queryBuildRange = queryBuildDataSource.addRange(fieldnum(CustTable, AccountNum));
}
// If an account number has not been set, then use the parameter value to set it.
if(!queryBuildRange.value())
        queryBuildRange.value(accountNum);
}
queryRun = new QueryRun(query);
while(queryRun.next())
{
custTable = queryRun.get(tableNum(CustTable));
this.insertTmpTable(CustTable);
}
}
________________________________________________
/// This method inserts data into the temporary table.
/// Table buffer of CustTable table.

private void insertTmpTable(CustTable _custTable)
{
custTableTmp.AccountNum = _custTable.AccountNum;
custTableTmp.Blocked = _custTable.Blocked;
custTableTmp.PriceGroup = _custTable.PriceGroup;
custTableTmp.Currency = _custTable.Currency;
custTableTmp.insert();

}
____________________________________________
[SRSReportDataSetAttribute("CustTableTmp")]
public custTableTmp getcustTableTmp()
{
select * from custTableTmp;
return custTableTmp;
}

Styel 2
// *************Alternative code sample*************//

SSRS report DP class And Contract Class Example
/// <summary>
///    The <c>LedgerJournalDP</c> class declares the variables, tables, and so on, that are used in the
///    <c>LedgerJournal</c> report.
/// </summary>
[
    SRSReportQueryAttribute(queryStr(HcmWareHouseQry)),
    SRSReportParameterAttribute(classStr(WareHouseReportContract))
]
public class WarehouseReportDP extends SRSReportDataProviderBase
{
    WarehouseTmp WarehouseTmp;
    TransDate    fromDate;
    TransDate    toDate;
 }
 private Query buildQuery(    Query                   _query,
                             FromDate                _fromDate,
                             ToDate                  _toDate)

    {
    if(_fromDate && _toDate)
        _query.dataSourceTable(tablenum(HcmWarehouseHeaderTable),1).addRange(fieldnum(HcmWarehouseHeaderTable, InvoiceDate)).value(queryRange(_fromDate,_toDate));
        return _query;
    }
 private void getReportParameters()
{
    WareHouseReportContract WareHouseReportContract = this.parmDataContract();
        fromDate         = WareHouseReportContract.parmFromDate();
        toDate           = WareHouseReportContract.parmTodate();
}
 // <summary>
/// Executes temporary table.
/// </summary>
/// <returns>
/// The temporary table <c>LedgerJournalTmp</c>.
/// </returns>
[
    SRSReportDataSetAttribute('WarehouseTmp')
]
public WarehouseTmp getWarehouseTmp()
{
    select WarehouseTmp;
    return WarehouseTmp;
}
 private void insertWarehouseTmp(
    HcmWarehouseHeaderTable _HcmWarehouseHeaderTable,
    HcmWarehouseLinesTable _HcmWarehouseLinesTable)
{
    WarehouseTmp.Logo           = _HcmWarehouseHeaderTable.image();
    WarehouseTmp.WarehouseID    = _HcmWarehouseHeaderTable.WarehouseID;
    WarehouseTmp.InvoiceNumber  = _HcmWarehouseHeaderTable.InvoiceNumber;
    WarehouseTmp.InvoiceDate    = _HcmWarehouseHeaderTable.InvoiceDate;
    WarehouseTmp.VendName       = _HcmWarehouseHeaderTable.VendName;
    WarehouseTmp.VendorAccount  = _HcmWarehouseHeaderTable.VendorAccount;
    WarehouseTmp.Address        = _HcmWarehouseHeaderTable.vendorAddress();
    WarehouseTmp.SerialNumber   = _HcmWarehouseLinesTable.SerialNumber;
    WarehouseTmp.ITAssetCode    = _HcmWarehouseLinesTable.ITAssetCode;
    WarehouseTmp.Type           = _HcmWarehouseLinesTable.Type;
    WarehouseTmp.Manufacturer   = _HcmWarehouseLinesTable.Manufacturer;
    WarehouseTmp.Model          = _HcmWarehouseLinesTable.Model;
    WarehouseTmp.ProductDescription = _HcmWarehouseLinesTable.ProductDescription;
    WarehouseTmp.BaseConfiguration  = _HcmWarehouseLinesTable.BaseConfiguration;
    WarehouseTmp.ProductSerialNumber = _HcmWarehouseLinesTable.ProductSerialNumber;
    WarehouseTmp.Quantity       = _HcmWarehouseLinesTable.Quantity;
    WarehouseTmp.AcquisitionCost = _HcmWarehouseLinesTable.AcquisitionCost;
    WarehouseTmp.WarrantyPeriod = _HcmWarehouseLinesTable.WarrantyPeriod;
    WarehouseTmp.insert();
}
 [SysEntryPointAttribute(false)]
public void processReport()
{
    HcmWarehouseHeaderTable HcmWarehouseHeaderTable;
    HcmWarehouseLinesTable HcmWarehouseLinesTable;
    WareHouseReportContract contract;
    QueryRun queryRun;
     this.getReportParameters();
    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),fromDate,toDate));
     while (queryRun.next())
    {
        HcmWarehouseHeaderTable = queryRun.get(tableNum(HcmWarehouseHeaderTable)) as HcmWarehouseHeaderTable;
        HcmWarehouseLinesTable = queryRun.get(tableNum(HcmWarehouseLinesTable)) as HcmWarehouseLinesTable;
        this.insertWarehouseTmp(HcmWarehouseHeaderTable, HcmWarehouseLinesTable);
     }
}
/// <summary>
///    The <c>LedgerJournalContract</c> class is the Data Contract class for the <c>LedgerJournal</c> SSRS
///    report.
/// </summary>
[
    DataContractAttribute,
    SysOperationGroupAttribute('PrintOut', "@SYS12608", '1')
]
public class WareHouseReportContract
{
    TransDate    fromDate;
    TransDate    toDate;
 }
 /// <summary>
/// Gets or sets the value of the datacontract parameter ShowAccrualTrans.
/// </summary>
/// <param name=”_showAccrualTrans”>
/// The new value of the datacontract parameter ShowAccrualTrans; optional.
/// </param>
/// <returns>
///  The current value of datacontract parameter ShowAccrualTrans
/// </returns>
[
    DataMemberAttribute('fromDate'),
    SysOperationLabelAttribute(literalstr("FromDate")),
    SysOperationHelpTextAttribute(literalstr("FromDate")),
    SysOperationGroupMemberAttribute('PrintOut'),
    SysOperationDisplayOrderAttribute('2')
]
public TransDate parmFromDate(TransDate _fromDate = fromDate)
{
    fromDate = _fromDate;
    return fromDate;
}
 // <summary>
/// Gets or sets the value of the datacontract parameter Specification.
/// </summary>
/// <param name=”_specification”>
/// The new value of the datacontract parameter Specification; optional.
/// </param>
/// <returns>
///  The current value of datacontract parameter Specification
/// </returns>
[
    DataMemberAttribute('todate'),
    SysOperationLabelAttribute(literalstr("Todate")),
    SysOperationHelpTextAttribute(literalstr("Todate")),
    SysOperationGroupMemberAttribute('PrintOut'),
    SysOperationDisplayOrderAttribute('3')
]
public TransDate parmTodate(TransDate _todate = todate)
{
    todate = _todate;
    return todate;
}

Regards,

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...