Month: July 2013

Export data to Excel using X++

HI,

Below sample code used to export data from Ax to Excel or text.

static void CSV_excel(Args _args)
{
Commaio file;
container line,header;
HcmWorker hcmWorker;
#define.filename(“C:\\dpk_Items3.csv”) //if we need text file to be genetated: use “.txt” as extension for the file”
#File

;
file = new Commaio(#filename , #io_write);// or file = new Commaio(#filename , ‘W’);
if( !file || file.status() != IO_Status::Ok)
{
throw error(“File Cannot be opened”);
}
header = [‘Empl code’,’..’, ‘recid’];
file.writeExp(header);
while select hcmWorker
{
line = [hcmWorker.TransferEmployeeCode,’…’,hcmWorker.RecId];
file.writeExp(line);
}
info(“Done”);
}

 

Custom look up in Form

Hi,

Below is the sample code used to build a custom lookup on control.

public void lookup()

{

Query query = new Query();

QueryBuildDataSource qbs;

QueryBuildRange qr;

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(MZK_Goals), this);

sysTableLookup.addLookupField(fieldNum(MZK_Goals, GoalNo));

sysTableLookup.addLookupField(fieldNum(MZK_Goals, Goals));

qbs = query.addDataSource(tableNum(MZK_Goals));

qr = qbs.addRange(fieldNum(MZK_Goals, HcmGoalType));

qr.value(MZK_MassGoalEnrollmentHeader_HcmGoalType.valueStr());

sysTableLookup.parmQuery(query);

sysTableLookup.performFormLookup();

}

SSRS : Contract Class & Debug it

Hi,

Below is the sample code to Develop the contract class.

Here I need to pass the “Date” as the parameter, based on the selected data I need to get the data.

1) [DataContractAttribute]

class SrsRDPContractIndemnity

{

StartDate        tillDate;

}

2)  [DataMemberAttribute(“Date”)]

public StartDate asOfDate(StartDate _tilldate = today())

{

tillDate = _tilldate;

return tillDate;

}

Debug the contact class: 

static void SSRS_ContractclsDEBUG(Args _args)

{

ProdRouteTrans  prodRouteTrans;

//ACWAPIPETotalItemProdPerMonthTmp  acwaPIPETotalItemProdPerMonthTmp;

MZK_PayrollIndemnityTmp payrollIndemnityTmp;

IndemnityRDP dataprovider = new IndemnityRDP();

SrsRDPContractIndemnity    contract    = new SrsRDPContractIndemnity();

;

contract.asOfDate(today());

dataProvider.parmDataContract(contract);

dataProvider.processReport();

payrollIndemnityTmp = dataProvider.getDate();

}

SSRS : RDP class & Debug it

HI,

Below is the sample code for developing RDP class for SSRS reports

[SRSReportQueryAttribute (querystr(HcmWorkerListPage_Perment)), //My Query

SRSReportParameterAttribute(classStr(SrsRDPContractIndemnity))] //class name

1) class IndemnityRDP extends SRSReportDataProviderBase

{

MZK_PayrollIndemnityTmp        tmpPayrollIndemnity;

Mzk_PayrollIndemnityonly       payrollIndemnityonlycls;

}

2)

[SRSReportDataSetAttribute(“MZK_PayrollIndemnityTmp”)] //tmp table

Public MZK_PayrollIndemnityTmp getDate()

{

select * from tmpPayrollIndemnity;

return tmpPayrollIndemnity;

}

3)

[SysEntryPointAttribute(false)]

public void processReport()

{

QueryRun                    queryRun;

Query                       query;

    SrsRdpContractIndemnity  dataContract;

QueryBuildRange             qbrHcmWorker;

QueryBuildRange             qbrJourTrans;

StartDate                   tillDate;

QueryBuildDataSource          qbsHcmworker;

HcmWorker                   getHcmworker;

// Get the query from the runtime using a dynamic query.

query = this.parmQuery();

// Get the parameters passed from runtime.

dataContract    = this.parmDataContract();

tillDate = dataContract.asOfDate();

// Add parameters to the query.

qbsHcmworker = query.dataSourceTable(tablenum(HcmWorker));

if(tillDate)

{

qbrHcmWorker = qbsHcmworker.findRange(fieldnum(HcmWorker, NewHcmEmployeeType));

// If an invent JournalId has not been set, then use the parameter value to set it.

if(!qbrHcmWorker.value())

qbrHcmWorker.value(int2str(any2int(MZK_EmployeeType::Permanent)));

}

// Run the query with modified ranges.

queryRun    = new QueryRun(query);

ttsbegin;

while (queryRun.next())

{

getHcmworker = queryRun.get(tableNum(HcmWorker));

this.insertTmpTable(getHcmworker, tillDate);

}

ttsCommit;

}

4)

private void insertTmpTable(HcmWorker _hcmWorker,

StartDate  _tilldate=today())

{

HcmPayrollLine      hcmPayrollLline;

HcmEmployment       hcmEmployment;

utcDateTime         joinDateTime;

date                joinDate;

 

payrollIndemnityonlycls = new Mzk_PayrollIndemnityonly();

tmpPayrollIndemnity.Worker                  =   _hcmWorker.RecId;

tmpPayrollIndemnity.NewHcmEmployeeType      =   _hcmWorker.NewHcmEmployeeType;

tmpPayrollIndemnity.CitizenshipCountryRegion=   _hcmWorker.Nationality();

tmpPayrollIndemnity.Joindate                =   _hcmWorker.Joindate();

tmpPayrollIndemnity.Tilldate                =   _tilldate;

tmpPayrollIndemnity.Name                    =   _hcmWorker.name();

tmpPayrollIndemnity.Service                 =   (_tilldate – tmpPayrollIndemnity.Joindate)/365;

joinDateTime = DateTimeUtil::applyTimeZoneOffset(    hcmEmployment::findByWorker(_hcmWorker.RecId).ValidFrom, DateTimeUtil::getUserPreferredTimeZone());

joindate = any2date(joinDateTime);

tmpPayrollIndemnity.Indemnity   =   payrollIndemnityonlycls.payrollGeneration(_hcmWorker.RecId,joindate,_tilldate);

tmpPayrollIndemnity.insert();

}

Debug code for RDP:

static void SSRS_RDPclsDEBUG(Args _args)

{

//MachineBreakDownSlipTmp ACWATransferhistoryTmp;

MZK_PayrollIndemnityTmp payrollIndemnityTmp;

IndemnityRDP dataprovider = new IndemnityRDP();

//MachineBreakDownSlip_queryDP dataprovider = new MachineBreakDownSlip_queryDP();

dataProvider.processReport();

payrollIndemnityTmp = dataProvider.getDate();

}

Query build range while opening the form

HI,

Below sample code will be useful to build the query range and get data based on month while opening from only.

class declaration()

int month;

Form init()

                      month = 12

Datasource init()

                super();

queryBuildRange = Mzk_JapanesPayrollEntry_ds.query().dataSourceTable(tableNum(Mzk_JapanesPayrollEntry)).addRange(fieldNum(Mzk_JapanesPayrollEntry, Mthyr));

DS execute qury()

public void executeQuery()

{

    //queryBuildRange.value(int2str(any2int(sdate)));

      queryBuildRange.value(int2str(any2int(month)));

    super();

}

default code used in Ep

I)                   DLL

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Microsoft.Dynamics.Framework.Portal.UI.WebControls;

using Microsoft.Dynamics.Framework.Portal.UI.WebControls.WebParts;

using Proxy = Microsoft.Dynamics.Framework.BusinessConnector.Proxy;

using Microsoft.Dynamics.Framework.BusinessConnector.Session;

using Microsoft.Dynamics.Framework.BusinessConnector.Adapter;

using Microsoft.Dynamics.AX.Framework.Services.Client;

using Microsoft.Dynamics.Framework.Portal.UI;

using Microsoft.Dynamics.AX.Framework.Portal.Data;

//using ApplicationProxy = Microsoft.Dynamics.Portal.Application.Proxy;

using Microsoft.Dynamics.Framework.Portal;

II)                To get ax session ids:

private ISession AxSession

{

get

{

AxBaseWebPart webpart = AxBaseWebPart.GetWebpart(this);

return webpart == null ? null : webpart.Session;

 

}

}

III )  To get field value

#region Other functions

static AxBoundField GetField(DataControlFieldCollection fields, string name)

{

foreach (DataControlField field in fields)

{

AxBoundField boundField = field as AxBoundField;

if (boundField != null && String.Compare(boundField.DataField, name, true) == 0)

return boundField;

}

return null;

}

#endregion

Example :

AxBoundField StartDate = (AxBoundField)GetField(this.AxGroup1.Fields, “StartDate”);

Useful links for EP development

Hi,

Below links will be more useful for EP development.

Lookups in C#: http://msdn.microsoft.com/en-us/library/cc623636.aspx

EP cook book:

https://docs.google.com/viewer?a=v&q=cache:ucX9Zzr23JQJ:dynamicsuser.net/cfs-filesystemfile.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.21.55/Enterprise-Portal-Development-Cookbook.pdf+assign+value+to+the+bound+field+in+c%23+ax+2012&hl=en&gl=bh&pid=bl&srcid=ADGEESggbJsBoExEx7Lj9Qhep8clD2ob3dxS5Eop1mekdtlOFWqtCXmMohmm-bbW5bsr9InKoXXDny_CN9rpeEL9A4bpVJfMjRnZX_L5txuQoG69uR0_IJ5qe_PwZkxFGorwGDQTMFgy&sig=AHIEtbRUlWTmfcO8pL1psNZO_FzxVOIw4A

 

Calling X++ methods and using in it c# :

http://msdn.microsoft.com/EN-US/library/hh812513.aspx