Look up date and calendar in AX


Look up date and calendar in AX

void lookup()
{
ProjPeriodId    projPeriodId = DNGRMParameter::find().PeriodId;
ProjPeriodTo    projPeriodTo;
ProjControlPeriod  projControlPeriod = new ProjControlPeriod();
// projControlPeriod = element.args().caller().runbase();
//if (!projControlPeriod.parmPeriodic())
//{
//if (this.dateValue())
//{
//projPeriodTo = this.dateValue();
//}
//else
//{
//projPeriodTo = ProjPeriodLine::findPrevFromDate(projPeriodId, systemdateget()).PeriodTo;
//}
//}
//else
//{
if (this.dateValue())
{
projPeriodTo = this.dateValue();
}
else
{
projPeriodTo = ProjPeriodLine::findPrevFromDate(projPeriodId, systemdateget()).PeriodTo;
}
// }

ProjPeriodLine::lookupPeriodTo(this, projPeriodId, projPeriodTo);
}

Filter Invent On -Hand based on WMSLocation


Today I have faced a issue how to show or filter data on InventSum Grid in EP from WMSLocation i.e. for each location there should be Invent On-hand data.

Same as AX 2012 R3 rich client in EP.

For these following are the steps:

  1. Create a Dataset EPInventGridOnHand.
  2. Add InventSum and InventDim table in datasource of EPInventGridOnHand dataset.
  3. Now on init() method of EPInventGridOnHand dataset we will get WMSLocation buffer with InventLocationId and WmsLocationId field value and write below code before dataset Init method super()

switch(element.args().dataset())

{
case(tableNum(WMSLocation)):
wmsLocation = element.args().record(); // Here wmsLocation is a global table buffer
break;
}

For filtering based on WMSLocation write below code after dataset init method super()

               //Filter Invent On-hand based on WMSlocation

inventDim_ds.query().dataSourceTable(tableNum(InventDim)).addRange(fieldnum(InventDim,wmsLocationId)) .                                   value(queryValue(wmsLocation.wMSLocationId));

inventDim_ds.query().dataSourceTable(tableNum(InventDim)).addRange(fieldnum(InventDim,InventLocationId)) .                                 value(queryValue(wmsLocation.inventLocationId));

              //This will group by Onhand based on Item

inventSum_ds.query().dataSourceTable(tableNum(Inventsum)).addGroupByField(fieldNum(Inventsum, ItemId));

             //This will add fields in InventSum run time with clubbing the values.
InventSum::queryAddSumFields(inventSum_DS.query().dataSourceTable(tableNum(InventSum)));

Thanks

Arun Garg

Add Serial number field to any table and increment that according to Different Name


Learn Dynamics Ax with Johnkrish

Code:

public void modifiedField(FieldId _fieldId)
{
FormLetterRemarks formLetterRemarks;
super(_fieldId);
select count(FormLetter) from formLetterRemarks where formLetterRemarks.FormLetter == this.FormLetter;
if(formLetterRemarks.FormLetter == 0)
{
this.Seq_Number = 1;
}
else
{
this.Seq_Number = formLetterRemarks.FormLetter + 1;
}
}

OUTPUT

  • For Packing Slip it starts from 1
  • For Invoice also it starts from 1

Sequence

View original post

Find axbound field on EP


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;
}

Custom lookup on EP


To provide an ASP.Net text box to work as AX lookup field, need to follow following steps
1-Creae a new text box in page (Out of AXForm)
2-Add new ax lookup control from tool box
3-Set target control as added text box by using Lookup control’s target properly
4-If you want to show filtered data on the lookup then chose lookup types as CustomDataSet
5-To define lookup dataset use lookupControl’s Lookup event and set lookupDataSet by using following pattern code

protected void LookupFieldName_Lookup(object sender, AxLookupEventArgs e)
{
//Getcurrent user to filter record based on current user
String usr = WindowsIdentity.GetCurrent().Name;
int pos = usr.IndexOf(‘\\’);
usr = pos != -1 ? usr.Substring(pos + 1) : usr;
AxLookup lookup = (AxLookup)sender;

// Create the lookup data set. The respective table will be used.
Proxy.SysDataSetBuilder sysDataSetBuilder;
sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(AxSession.AxaptaAdapter,TableMetadata.TableNum(AxSession, “TableName”));

// Set the generated data set as the lookup data set.
lookup.LookupDataSet = new DataSet(AxSession, sysDataSetBuilder.toDataSet());
using (Proxy.Query query = lookup.LookupDataSet.DataSetViews[0].MasterDataSource.query())
{
query.dataSourceNo(1).addRange(TableArrayFieldMetadata.FieldNum(this.AxSession, “TableName”, “FieldName”)).value = “ValueInStringFormat”
//Example String.Format(“{0:dd/MM/yyyy}..{1}”, System.DateTime.Today, DateTime.MaxValue.ToShortDateString());

}

// Specify the fields for the lookup.
lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields[“Field1”]));
lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields[“Field2”]));
lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields[“Field3”]));
lookup.Fields.Add(AxBoundFieldFactory.Create(AxSession, lookup.LookupDataSetViewMetadata.ViewFields[“Field4”]));
// Specify the select field for the lookup.
lookup.SelectField = “Index/LookupFieldName”;

Upload document through EP in AX


To provide document attachement feature on EP form to upload documents, need to follow below setps 

1-Add new datasource by using EPDocuInfoAdd data set from AX
2-Add new ASP:FileUpload control on page
3-On Ok/Submit button call below method after Inserting/Updating recordprivate void DocumentUpload()
{
DataSetView datasetViewAppl = DataSourceName.GetDataSourceView(AXFormControlName.DataMember).DataSetView;

DataSetViewRow docuRefAdd = this.dsDocuRef.GetDataSourceView(“DocuRef”).DataSetView.AddNew();
DataSetViewRow docuRefCurrent = this.dsDocuRef.GetDataSourceView(“DocuRef”).DataSetView.GetCurrent();

IAxaptaRecordAdapter docuRefRecord = docuRefCurrent.GetRecord();
docuRefRecord.SetField(“RefTableId”, (object)datasetViewAppl.GetCurrent().GetFieldValue(“TableId”));
docuRefRecord.SetField(“RefRecId”, (object)datasetViewAppl.GetCurrent().GetFieldValue(“RecId”));
docuRefRecord.SetField(“TypeId”, “File”);

string[] myFiles = Request.Files.AllKeys;
bool dataSaved = false;
if (FileUpload1.HasFile)
{
using (IAxaptaRecordAdapter irecDocuValue = ApplicationProxy.EPDocumentHandling.saveWebDocumentClient(
AxSession.AxaptaAdapter,
docuRefRecord,
Request.Files.AllKeys[0]))
{
{
if (irecDocuValue != null)
{
// Get the RecId of the insert DocuValue record.
Int64 valueRecId = (Int64)irecDocuValue.GetField(“RecId”);

if (valueRecId != 0)
{
//Update the ValueRecId field of the DocuRef record with the RecId of the DocuValue record
docuRefRecord.SetField(“ValueRecId”, (object)valueRecId);

// Saves the DocuRef record in the DB.
ApplicationProxy.EP.createDocuRef(AxSession.AxaptaAdapter, docuRefRecord);

// Set this parameter to enable redirection.
dataSaved = true;
}
else
throw new System.Exception(“File upload error”);
}
}
}

HOW TO DEVELOP A NEW “PARAMETERS FORM” IN CASE OF NEW MODULE DEVELOPED IN AX.


D365 Smart - Technical Blog on Microsoft D365 Fin & Ops

Hi,

How to develop a new “Parameters form” in case of New Module developed in AX.We go through it by considering an example of creating the new module as Payroll.So now we will create the Payroll Parameters setup form for the payroll module.Initially create a Parameters table for the Module, the naming convention should be the Module name followed by Parameter as in this case it is PayrollParameters table….and need to have the fields accordingly what is required in the Parameters table.Set the following properties for the parameter table as…
Create a parameter form by considering the PayrollParameters and NumberSequenceReference as data sources. And set the following properties for the data source in the form level as
First thing is that there shouldn’t be any provision to create the record in the parameters form. The record in the Parameters should be by default and it can be…

View original post 106 more words

How to use Event Handler in Microsoft Dynamics AX 2012:


D365 Smart - Technical Blog on Microsoft D365 Fin & Ops

Hi,

Microsoft incorporated lot of beautiful new features in Dynamics AX 2012 and one of them is Event Handler. It’s a very nice feature of Dynamics AX 2012 which allows you trigger an event after or before an activity.
So today am going to tell you about these features:
In Microsoft Dynamics AX 2012 how to handle event on different methods / occurrences.

In Microsoft Dynamics AX 2012 how to implement or apply pre or post event handler.
How to develop an event handler step by step in Microsoft Dynamics AX 2012.
What is new in Microsoft Dynamics AX 2012 from programming point of view?
X++ Event handling in Dynamics AX 2012.

You should invoke events over using pre or post events on methods.

Pre-Event Handlers and Post-Event Handlers

An event handler can reside underneath a method node can run either before or after the method runs. You can use…

View original post 619 more words