Tuesday, April 11, 2017

Report Development in Ax 2012

I Have created new temp table what fields i want show in the Report.
Table Name : TransferInOutTmp                      
Contract Class: A data contract class is an X++ class which contains parm methods with the DataMemberAttribute defined at the beginning of the method. 
This class is used to define one or more parameters that will be used in a SSRS report.
[
DataContractAttribute,
SysOperationContractProcessingAttribute(classStr(TransferInOutUIBuilder))
]
public class TransferInOutContract implements SysOperationValidatable
{
     TransDate           fromDate;
     TransDate           toDate;
     InventSiteId        site;
     NoYes               shipdate,Recdate;

 }

[
   DataMemberAttribute(identifierStr('TransDate')),
    SysOperationLabelAttribute(literalstr("From Date")),
    SysOperationHelpTextAttribute(literalstr("From Date")),
    SysOperationDisplayOrderAttribute('1')
]
public TransDate parmFromDate(TransDate _fromDate = fromDate)
{
    fromDate = _fromDate;
    return fromDate;

}
[
   DataMemberAttribute(identifierStr('toDate')),
    SysOperationLabelAttribute(literalstr("To Date")),
    SysOperationHelpTextAttribute(literalstr("To Date")),
    SysOperationDisplayOrderAttribute('2')
]
public TransDate parmToDate(TransDate _toDate = toDate)
{
    toDate = _toDate;
    return toDate;

}
[
    DataMemberAttribute('InventSiteId'),
    SysOperationLabelAttribute(literalstr("Site Id")),
    SysOperationHelpTextAttribute(literalstr("Site Id")),
    SysOperationDisplayOrderAttribute('3')
]
public InventSiteId parmsite(InventSiteId _site = site)
{
    site = _site;
    return site;

}
[
   DataMemberAttribute(identifierStr('ReceiptDate')),
    SysOperationLabelAttribute(literalstr("Received")),
    SysOperationHelpTextAttribute(literalstr("Received")),
    SysOperationDisplayOrderAttribute('5')
]
public NoYes parmrecdate(NoYes _Recdate = Recdate)
{
    Recdate = _Recdate;
    return Recdate;

}
[
   DataMemberAttribute(identifierStr('NoYes')),
    SysOperationLabelAttribute(literalstr("Shipped")),
    SysOperationHelpTextAttribute(literalstr("Shipped")),
    SysOperationDisplayOrderAttribute('4')
]
public NoYes parmshipdate(NoYes _shipdate = shipdate)
{
    shipdate = _shipdate;
    return shipdate;

}
public boolean validate()
{
    boolean ret = true;

    if (fromDate > toDate)
    {
        ret = checkFailed("From date is later than to date");
    }

    return ret;

}

DP Class :This method contains the business logic and is called by reporting services to generate data.
[
SRSReportParameterAttribute(classStr(TransferInOutContract))
]
class TransferInOutDP extends SRSReportDataProviderBase
{
    TransferInOutTmp                       transferInOutTmp; //temp table
    TransferInOutContract                contract;
    InventTransferTable                    transferTable;
    InventTransferLine                     transferLine;
    InventTransferReceiveDate        fromdate,todate;
    InventSiteId                                 siteId;
    InventLocation                            location,locationloc;
    NoYes                                         shipdate,Recdate;

}
[SRSReportDataSetAttribute("TransferInOutTmp")]
public TransferInOutTmp getTmptransferInOut()
{
    select * from transferInOutTmp;
    return transferInOutTmp;
}
public void insertTransferInOut(InventTransferTable   _inventTransferTable,InventTransferLine  _inventTransferLine)
{
  transferInOutTmp.InventTransferId  = _inventTransferTable.TransferId;
  transferInOutTmp.FromWarehouse     = _inventTransferTable.InventLocationIdFrom;   transferInOutTmp.FromSiteName  =  InventLocation::find(transferInOutTmp.FromWarehouse).Name;
 transferInOutTmp.ToWarehouse       = _inventTransferTable.InventLocationIdTo;
  transferInOutTmp.ToSiteName        = InventLocation::find(transferInOutTmp.ToWarehouse).Name;
    transferInOutTmp.ItemId            = _inventTransferLine.ItemId;
    transferInOutTmp.ItemName          = _inventTransferLine.itemName();
      transferInOutTmp.TransferStatus    = _inventTransferTable.TransferStatus;
    transferInOutTmp.ReceiveDate       = _inventTransferTable.ReceiveDate;
    transferInOutTmp.ShipDate          = _inventTransferTable.ShipDate;
    transferInOutTmp.insert();
}
[SysEntryPointAttribute(false)]
public void processReport()
{
    Query                   query = new Query();
    QueryRun                         queryRun;
    QueryBuildDataSource    qbdstransferTable;
    QueryBuildDataSource    qbdstransferLine;
    QueryBuildDataSource    qbdsLocation;
    QueryBuildRange         qbr,qbr1,qbr2,qbr3,qbrshipped,qbrreceived;
   

    contract = this.parmDataContract() as TransferInOutContract;
    fromDate        =   contract.parmFromDate();
    toDate          =   contract.parmToDate();
    siteId          =   contract.parmsite();
    shipdate        =   contract.parmshipdate();
    Recdate         =   contract.parmrecdate();


    qbdstransferTable   = query.addDataSource(tableNum(InventTransferTable));
    qbdstransferLine =   qbdstransferTable.addDataSource(tableNum(InventTransferLine));
    qbdstransferLine.relations(true);
    qbdstransferLine.joinMode(JoinMode::InnerJoin);
    if(shipdate)
    {
        qbdstransferTable.addRange(fieldNum(InventTransferTable, ShipDate)).value(SysQuery::range(fromDate, toDate));
        qbdstransferTable.addRange(fieldNum(InventTransferTable,TransferStatus)).value(enum2str(InventTransferStatus::Shipped));
    }
    if(Recdate)
    {
        qbdstransferTable.addRange(fieldNum(InventTransferTable, ReceiveDate)).value(SysQuery::range(fromDate, toDate));
        qbdstransferTable.addRange(fieldNum(InventTransferTable,TransferStatus)).value(enum2str(InventTransferStatus::Received));
    }

    queryRun = new QueryRun(query);
    while (queryRun.next())
    {
        transferTable     = queryrun.get(tableNum(InventTransferTable));
        transferLine      = queryrun.get(tableNum(InventTransferLine));
        if (siteId)
        {
            location = InventLocation::find(transferTable.InventLocationIdFrom);
            if(siteId == location.InventSiteId)
            {
              this.insertTransferInOut(transferTable,transferLine);
            }
        }
    }
}

UI Builder :User Interface (UI) Builder Class is used to define the layout of the parameter dialog box that opens before a report is run in Microsoft Dynamics AX. It is used to add the customizations as well as additional fields in the dialog.
class TransferInOutUIBuilder extends SysOperationAutomaticUIBuilder
{
    Dialogfield                 dlgfromdate;
    Dialogfield                 dlgtodate;
    Dialogfield                 dlgsite;
    Dialogfield                 dialogreceiptdate;
    Dialogfield                 dialogshipdate;
   TransferInOutContract   contract;
}
public void Build()
{
    Dialog dialogObject =  this.dialog();

    contract =  this.dataContractObject();

    this.addDialogField(methodStr(TransferInOutContract,parmfromDate),contract);
    this.addDialogField(methodStr(TransferInOutContract,parmtoDate),contract);
    this.addDialogField(methodStr(TransferInOutContract,parmsite),contract);

    dialog.addGroup("Shipped");
    this.addDialogField(methodStr(TransferInOutContract,parmshipdate),contract);
    dialog.addGroup("Received");
    this.addDialogField(methodStr(TransferInOutContract,parmrecdate),contract);
}
public void initializefields()
{
    contract = this.dataContractObject();
 }
/// <summary>
/// This method is used to initialize the dialog fields after the fields are build.
/// </summary>
public void postBuild()
{
    super();

     contract = this.dataContractObject();
     dlgfromdate         = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TransferInOutContract, parmFromDate));
     dlgfromdate.fieldControl().mandatory(true);
     dlgtodate           = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TransferInOutContract, parmToDate));
     dlgtodate.fieldControl().mandatory(true);
     dlgsite             = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TransferInOutContract, parmsite));
     dlgsite.fieldControl().mandatory(true);
     dialogreceiptdate   = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TransferInOutContract, parmrecdate));
     dialogshipdate      = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TransferInOutContract, parmshipdate));

     dialogreceiptdate.registerOverrideMethod(methodStr(FormCheckBoxControl, modified), methodStr(TransferInOutUIBuilder, receivedModified), this);
     dialogshipdate.registerOverrideMethod(methodStr(FormCheckBoxControl, modified), methodStr(TransferInOutUIBuilder, shipModified), this);
}

public boolean receivedModified(FormCheckBoxControl _control)
{
    dialogshipdate.value(_control.checked(false));
    return true;
}

public boolean shipModified(FormCheckBoxControl _control)
{
  dialogreceiptdate.value(_control.checked(false));
   return true;
}
Develop a Report in Visual Studio and create a one output menuItem 
based on selection report will generate.


Thursday, March 23, 2017

The Accounts Payable cube cube either does not exist or has not been processed.

After deployed the Cubes showing error message :
The Accounts Payable cube cube either does not exist or has not been processed. 

Solution:
System Administrator > Setup > Business Intelligence > Analysis Services > Analysis Servers
 Configure the Default Database "Dynamics initial" in OLAP database TabPage





Sunday, March 5, 2017

How to update Label Id to String through X++ code

static void Lableid2str(Args _args)
{
RetailChannelReport     retailChannelReport;
;
ttsBegin;
while select forUpdate retailChannelReport
{
retailChannelReport.ReportName = SysLabel::labelId2String2(retailChannelReport.ReportName, 'en-us');
print retailChannelReport.ReportName;
retailChannelReport.doupdate();
 }
ttscommit;
pause;
}

Monday, November 7, 2016

How to change colour based on condition in form grid

Form > Datasource>Methods>displayOption

public void displayOption(Common _record, FormRowDisplayOption _options)
{
    Tablename    table;

    if(_record.RecId)
    {
        select  table where table.recid == _record.RecId;
        if(table.Status  == Status::Posted)
        {
            _options.textColor(WinAPI::RGB2int(250,1,1));
        }
    }
    super(_record, _options);
}

Saturday, August 20, 2016

Report Issues in Ax 2012

1 . Problem :
Error while setting server report parameters. Error message: The DefaultValue expression for the report parameter ‘AX_CompanyName’ contains an error: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (rsRuntimeErrorInExpression) in ax 2012

Solution:

http://rahulmsdax.blogspot.in/2015/02/error-while-setting-server-report.html

2 . Problem: 

Publish-AXReport -ReportName *
i got an error:
...
Publish-AXReport : A call to the Microsoft Dynamics AX SRSFrameworkService
service failed. An existing connection was forcibly closed by the remote host.
At line:1 char:1
+ Publish-AXReport -ReportName *
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (Microsoft.Dynam...shReportCommand:Pu
blishReportCommand) [Publish-AXReport], ReportException
+ FullyQualifiedErrorId : A call to the Microsoft Dynamics AX SRSFramework
Service service failed. An existing connection was forcibly closed by the
remote host.,Microsoft.Dynamics.AX.Framework.Management.Reports.PublishRep
ortCommand
....
but i can deploy a single report by its name only, not all at the same command!!

Solution:

Start > Administrative Tools > Microsoft Dynamics AX 2012 Management Shell

run the below script:

foreach ($letter in 97..122) 
{
Publish-AXReport -ReportName "$([char]$letter)*"
}


3.Problem:

Publish-AXReport : Client found response content type of '', but expected
'text/xml'.The request failed with an empty response.
At line:1 char:1
+ Publish-AXReport -ReportName *
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (Microsoft.Dynam...shReportCommand:Pu
   blishReportCommand) [Publish-AXReport], InvalidOperationException
    + FullyQualifiedErrorId : Client found response content type of '', but ex
   pected 'text/xml'.
    The request failed with an empty response.,Microsoft.Dynamics.AX.Framework

   .Management.Reports.PublishReportCommand

Solution: Restart the Sql Server Reporting Service and try to deploy

Thursday, June 23, 2016

How to Get HcmWorker Financial dimensions in ax 2012

add the below code in HcmWorker Table method.

public static str getDimensionValue(HcmWorkerRecId _workerRecId,Name _DimensionName,
                                            utcdatetime _asOfDate = DateTimeUtil::utcNow())
{
    DimensionAttributeValueSetStorage             dimStorage;
    str                                                                dimValue;
    Counter                                                     counter;
    HcmEmployment                                 hcmEmployment;
    RecId                                                 _DefaultDimension;
    ;
    select hcmEmployment where
              hcmEmployment.Worker == HcmWorker::find(_workerRecId).RecId;

    dimStorage = DimensionAttributeValueSetStorage::find(hcmEmployment.DefaultDimension);

    for (counter=1 ; counter<= dimStorage.elements(); counter++)
    {
         if(DimensionAttribute::find(dimStorage.getAttributeByIndex(counter)).Name == _DimensionName)
         {
               dimValue = dimStorage.getDisplayValueByIndex(counter);
              // info(strfmt('%1',dimValue));
         }
    }
    return dimValue;
}

after show make a display method to financial methods.

Idisplay HcmPersonnelNumberId branch( )
{
return HcmWorker::getDimensionValue(HcmWorker::findByPersonnelNumber(this.PersonnelNumber).RecId, 'BRANCH');

}


Thursday, February 4, 2016

How to generate serial number only visible records in SSRS Report

S.NO> function

=RunningValue( IIf(Fields!Payable.Value <= 0, Nothing, Fields!Payable.Value)
    , CountDistinct
    , "Tablix1")

update_recordset with joins

 update_recordset with joins update_recordSet storeTransfer         setting      TransactionId = transfertable.TransferId     join transfert...