Alfasith AX

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

Wednesday, July 24, 2013

Creating the Query in job - Dynamic AX

static void CustTableSales1(Args _args)

{
    Query       query;
    QueryRun    queryrun;
    QueryBuildDataSource    qbds1,qbds2;
    QueryBuildRange         qbr1,qbr2;
    CustTable               custTable;
    ;
    query   = new query();
    qbds1   =   query.addDataSource(tablenum(CustTable));
    qbds1.addSortField(fieldnum(custTable,AccountNum),Sortorder::Descending);
    qbr1    = qbds1.addRange(fieldnum(custTable,custGroup));
    qbr1.value(queryvalue('10'));
    qbr2    =  qbds1.addRange(fieldnum(custTable,Blocked));
    qbr2.value(queryvalue(CustVendorBlocked::No));
    qbds2   = qbds1.addDataSource(tablenum(SalesTable));
    qbds2.relations(false);
    qbds2.joinMode(joinmode::ExistsJoin);
    qbds2.addLink(fieldnum(CustTable,AccountNum),fieldnum(SalesTable,CustAccount));
    queryrun    = new queryrun(query);
    while(queryrun.next())
    {
        custTable   = queryrun.get(tablenum(custTable));
        info(strfmt('%1 – %2',custtable.AccountNum,custTable.name()));
    }
}





//Another sample code///

Query                   query; 
QueryRun                queryRun; 
QueryBuildDataSource    queryBuildDataSource; 
QueryBuildRange         queryBuildRange; 
CustTable               custTable; 
query = new Query(); 
queryBuildDataSource = query.addDataSource(TableNum(CustTable)); 
queryBuildRange = queryBuildDataSource.addRange(FieldNum(CustTable,AccountNum)); 
queryBuildRange.value("4000..5000"); 
queryRun = new queryRun(query); 
if (queryRun.prompt()) 
{ 
    while (queryRun.next()) 
    { 
        custTable = queryRun.get(TableNum(CustTable)); 
        print custTable.AccountNum; 
    } 
}

How to add multiple parameter in to SSRS report as Query range in Dynamic AX

Hi,
Adding the fields in the Contract directly reflect on the parameter fields in the report dialog.
Adding the QueryBuildRange and its datasource makes the querying of the ranges value.

CategoryContractClass:
[
    DataContractAttribute,
    SysOperationGroupAttribute('Case', "Case",'1'),
    SysOperationGroupAttribute('Date', "Date",'2'),
    SysOperationGroupAttribute('PrintOut', "@SYS12608", '3')

]
public class CategoryContract implements SysOperationValidatable
{

    FromDate   FromDate;
    ToDate     ToDate;
    CaseCategoryType CaseCategoryType;
    CaseCategory CaseCategory;
}
/******************************************************************/
[
    DataMemberAttribute('CaseCategory'),
    SysOperationLabelAttribute(literalstr("Case Category")),
    SysOperationHelpTextAttribute(literalstr("Case Category")),
    SysOperationGroupMemberAttribute('Case'),
    SysOperationDisplayOrderAttribute('2')

]
public CaseCategory parmCaseCategory(CaseCategory _CaseCategory = CaseCategory)
{

    CaseCategory = _CaseCategory;
    return CaseCategory;

}
/******************************************************************/
[
    DataMemberAttribute('CaseCategoryType'),
    SysOperationLabelAttribute(literalstr("Category Type")),
    SysOperationHelpTextAttribute(literalstr("Category Type")),
    SysOperationGroupMemberAttribute('Case'),
    SysOperationDisplayOrderAttribute('1')

]
public CaseCategoryType parmCaseCategoryType(CaseCategoryType _CaseCategoryType = CaseCategoryType)
{

    CaseCategoryType = _CaseCategoryType;
    return CaseCategoryType;

}

/******************************************************************/
[
    DataMemberAttribute('FromDate'),
    SysOperationLabelAttribute(literalstr("From Date ")),
    SysOperationHelpTextAttribute(literalstr("From Date")),
    SysOperationGroupMemberAttribute('Date'),
    SysOperationDisplayOrderAttribute('1')

]
public FromDate parmFromDate(FromDate _FromDate = FromDate)
{

    FromDate = _FromDate;
    return FromDate;

}

/******************************************************************/
[
    DataMemberAttribute('ToDate'),
    SysOperationLabelAttribute(literalstr("To Date")),
    SysOperationHelpTextAttribute(literalstr("ToDate")),
    SysOperationGroupMemberAttribute('Date'),
    SysOperationDisplayOrderAttribute('2')

]
public ToDate parmToDate(ToDate _ToDate = ToDate)
{

    ToDate = _ToDate;
    return ToDate;

}

/******************************************************************/
public boolean validate()
{
    boolean             isValid = true;
    if (!CaseCategoryType)
    {
        isValid = checkFailed("Category Type should be entered");
    }
     return isValid;
}
/******************************************************************/
CategoryDPClass
[
SRSReportQueryAttribute(queryStr(CategoryQry)),
SRSReportParameterAttribute(classStr(CategoryContract))
]
class CategoryDP extends SRSReportDataProviderBase
{
    CategoryTmp  CategoryTmp;
    CaseCategory CaseCategory;
    CaseCategoryType CaseCategoryType;
    FromDate FromDate;
    ToDate ToDate;
}
/******************************************************************/
private Query buildQuery( Query             _query,
                          CaseCategoryType  _CaseCategoryType,
                          CaseCategory      _CaseCategory,
                          FromDate          _FromDate,
                          ToDate            _ToDate)
    {

        if(_CaseCategoryType)
            _query.dataSourceTable(tablenum(CaseCategoryHierarchyDetail),1).addRange(fieldnum(CaseCategoryHierarchyDetail, CategoryType)).value(queryValue(_CaseCategoryType));

       if(_CaseCategory)
           _query.dataSourceTable(tablenum(CaseCategoryHierarchyDetail),1).addRange(fieldnum(CaseCategoryHierarchyDetail, CaseCategory)).value(queryValue(_CaseCategory));

        if(_FromDate && _ToDate)
          _query.dataSourceTable(tablenum(CaseDetailBase),1).addRange(fieldnum(CaseDetailBase, CreatedDateTime)).value(queryRange(_FromDate,_ToDate));

        return _query;

     }
/******************************************************************/
[
SRSReportDataSetAttribute(tableStr(CategoryTmp))
]
public CategoryTmp getCategoryTmp()
{

    select * from CategoryTmp;
    return CategoryTmp;

}
/******************************************************************/
private void getReportParameters()
{

    CategoryContract CategoryContract = this.parmDataContract();
    if (CategoryContract)
     {

         CaseCategoryType     = CategoryContract.parmCaseCategoryType();
         CaseCategory         = CategoryContract.parmCaseCategory();
         FromDate             = CategoryContract.parmFromDate();
         ToDate               = CategoryContract.parmToDate();

     }

 }
/******************************************************************/
public void InsertCategoryTmp(CaseDetailBase _CaseDetailBase,CaseCategoryHierarchyDetail _CaseCategoryHierarchyDetail)
{
    HcmWorker HcmWorker;
    DirPartyTable DirPartyTable;
    CaseDetailBase CaseDetailBase;
    CategoryTmp.CaseId      = _CaseDetailBase.CaseId;
    CategoryTmp.Logo        = CompanyImage::findByRecord(CompanyInfo::find()).Image;
   // CaseCategoryTmp.Name        = _CaseDetailBase.displayOwnerName();
    CategoryTmp.Status      = _CaseDetailBase.Status;
    CategoryTmp.Description = _CaseDetailBase.Description;
    CategoryTmp.Priority    = _CaseDetailBase.Priority;
   // CaseCategoryTmp.OwnerWorker = _CaseDetailBase.OwnerWorker;
    select DirPartyTable join HcmWorker join CaseDetailBase where DirPartyTable.RecId == HcmWorker.Person
                          && CaseDetailBase.CaseId == _CaseDetailBase.CaseId
                          && CaseDetailBase.OwnerWorker == HcmWorker.RecId;
    CategoryTmp.Name = DirPartyTable.Name;

    CategoryTmp.DateTime    = _CaseDetailBase.createdDateTime;
    CategoryTmp.CategoryType = _CaseCategoryHierarchyDetail.CategoryType;
    CategoryTmp.CaseCategory = _CaseCategoryHierarchyDetail.CaseCategory;
    CategoryTmp.insert();

}
/******************************************************************/
[SysEntryPointAttribute(false)]
public void processReport()
{

    CaseDetailBase              CaseDetailBase;
    CaseCategoryHierarchyDetail CaseCategoryHierarchyDetail;
     QueryRun queryrun;
    ;
    this.getReportParameters();
    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),CaseCategoryType,CaseCategory,FromDate,ToDate));
    //queryRun = new QueryRun(this.parmQuery());
    while(queryRun.next())
    {
         CaseDetailBase                   =queryrun.get(tableNum(CaseDetailBase));
         CaseCategoryHierarchyDetail      =queryrun.get(tableNum(CaseCategoryHierarchyDetail));
        this.InsertCategoryTmp(CaseDetailBase , CaseCategoryHierarchyDetail);
    }
}
/******************************************************************/

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