Search This Blog

Wednesday, 17 December 2014

How to Validate the Special Characters from the given String in Ax 2012

Hi,

Today I would like to share a X++ code to validate the special characters from the given string

static void RemoveSpecialCharacters(Args _args)
{str stringVar1,stringVar2;

//String with special characters and numbers
stringVar1= test!@#$%^&*(){}[]|\+-;,.?/~`12344;

//String without Special characters and  numbers
stringVar2=strRem(strAlpha(stringVar1),"1234567890");

if(stringVar2!=stringVar1 )
{          throw error("Enter Valid data");
}else
{            info("ok");
}
}
Happy Daxing...........
 

Thursday, 4 December 2014

X++ code to get the Phone Number of the Delivery Address in the Purchase Order in AX 2012

Hi,
 
Today I would like to share you , how to get the phone number of the Delivery Address in the Purchase Order.
 
static void getphoneNumber(Args _args)
{
 
PurchTable purchTable;
 
LogisticsLocation logisticslocation;
 
LogisticsPostalAddress logisticsPostalAddress;
 
select purchTable where purchTable.PurchId=="000059";
 
select logisticslocation where logisticslocation.ParentLocation ==
LogisticsPostalAddress::findRecId(purchTable.DeliveryPostalAddress).Location;
 
info(LogisticsElectronicAddress::findByLocation(logisticslocation.RecId).Description);
 
info(LogisticsElectronicAddress::findByLocation(logisticslocation.RecId).Locator);
 
}
 
Happy Daxing.........
 

Monday, 13 October 2014

Displaying Graphs and Charts in Ax 2012 Form

Hi,

I would like to share you how to display data in graphs and charts in AX 2012 Forms

for an example i have displayed the customer details whose invoice amount is greater than 10000 and less than 20000

step 1:

create a new form called CustomerInvoiceAmountGraph

step 2:

add custInvoicaJour table as datasource

step 3 : 

override init() method and class declaration method

public class FormRun extends ObjectRun
{
      Graphics    graphics;
      CustInvoiceJour custinvoiceJourGraphValues;
      Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar chartToolbarControl;
}

public void init()
{
    super();
// create an runtime reference to the toolbar control
   chartToolbarControl = chartToolbarControlHost.control();
// bind the tool bar to the chart control by passing an instance of the chart control to it
    chartToolbarControl.set_ChartControl(graphControl.control());
   this.showchart();
}

step 4:

create a new method called showchart() where your logic is placed to display the customer data
whose invoice amount is greater than 10000 and less than 20000

void showchart()
{

// create an instance of the X++ to .NET abstraction class and bind it to the chart control

    graphics =  new Graphics();
    graphics.ManagedHostToControl(graphControl);

// set your abstracted chart options

    graphics.create();
    graphics.parmTitle("@SYS95906");
    graphics.parmTitleXAxis("CustAccount");
    graphics.parmTitleYAxis("Amount");

// populate the chart with data

while select CustInvoiceJour where  CustInvoiceJour.InvoiceAmount>=10000  && CustInvoiceJour.InvoiceAmount <=20000
    {
        graphics.loadData( CustInvoiceJour.InvoiceAccount,  ' ' , CustInvoiceJour.InvoiceAmount);
    }

    graphics.showGraph();

}

step 5:

Right click Design->New control->ManagedHost

select Microsoft.Dynamics.AX.Framework.Client.Controls.ChartToolBar


step 6:

Right click Design->New control->ManagedHost

select System.Windows.Forms.DataVisualization.Charting.Chart and change the name of the control as GraphControl

output:

Happy Daxing.....

Passing multiple selected record as a parameter form Form to Report

Hi ,

Today i would like to share, how to pass multiple selected record from Form as a parameter to
Report

step 1 : 

write this piece of code in the clicked of the button

void clicked()
{
    CustTable  custTable1;
    container   con;
    Args        args;
    str         multiSelectString;
    args = new Args();
    custTable1= CustTable_ds.getFirst(1);
    while (custTable1)
    {
        // storing recid of selected record in container
        con = conIns(con,1, custTable1.AccountNum);
        // converting container to string with comma separated
        multiSelectString = con2Str(con,',');
        custTable1= CustTable_ds.getNext(); // moves to next record
    }

    // passing string
    args.parm(multiSelectString);
    // calling menu item
    new MenuFunction(menuitemOutputStr(SampleReport), MenuItemType::Output).run(args);
}

step 2 :

write this piece of code in the init method of the report and change the query property userupdate as no



public void init()
{
   str multipleRecords;
    super();
    multipleRecords = element.args().parm();
  this.query().dataSourceTable(Tablenum(CustTable)).addRange(fieldNum(CustTable,AccountNum)).value(multipleRecords);
}

Happy Daxing....

Thursday, 9 October 2014

X++ code to Customize Customer InvoiceId in the format of SI-YYMM#####

Hi ,

I would like to share you , how to customize Customer Invoiceid in the format of SI-YYMM#####

Class used in this process is

SalesInvoiceJournalCreateBase

Method used is

initJournalHeader()

comment this below line

custInvoiceJour.InvoiceId= this.getJournalNumber();

and write the following code :

int HyphenPosition;

 

custInvoiceJour.InvoiceDate = this.updateDate();

 HyphenPosition=strFind(this.getJournalNumber(),'-',1,strLen(this.getJournalNumber()));

    custInvoiceJour.InvoiceId = subStr(this.getJournalNumber(),1,HyphenPosition)+
                                subStr(date2str(custInvoiceJour.InvoiceDate,321,2,0,2,0,2),1,4)+
                                subStr(this.getJournalNumber(),HyphenPosition+1,strLen(this.getJournalNumber())-HyphenPosition);


That's it .......
 

 
 

Friday, 3 October 2014

Execute MenuItems Through Code

Hi ,

Today I would like to share some syntax which is used to execute MenuItems through code

They are three types of Menuitems in AX:

1)Display - Which represents Forms
2)Output - Which represents Reports
3)Action - Which represents Class

Menu Items are represented by the MenuFuction class

Syntax :

MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemDisplayStr(MyDisplayMenuItem), MenuItemType::Display);
menuFunction.run();
 
 
MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemOutputStr(MyOutputMenuItem), MenuItemType::Output);
menuFunction.run();
 
 
MenuFunction menuFunction;
  
menuFunction = new MenuFunction(menuItemActionStr(MyActionMenuItem), MenuItemType::Action);
menuFunction.run();
  

Monday, 29 September 2014

Cascade+Restricted Concept in Ax 2012



Step 1:
Create 3 tables for an example :

Table 1- SheetTable, with Two fields Sheetid and sheetname
Table 2-PartitionTable with three fields sheetid , partitionid and sheetsize
Table 3-SheetPartitionTable with two fields partitionid and Shape 

Step 2:

1) Create a relationship between SheetTable and PartitionTable (Ex:PartitionTable.SheetID==SheetTable.SheetId) 

2) Create a relationship between PartitionTable and SheetPartitionTable(EX:SheetPartitionTable.PartitionID==PartitionTable.PartitionID)

Step 3:

1) Create Cascade DeleteAction between SheetTable and PartitionTable

2) Create Cascade+Restricted DeleteAction between PartitionTable and SheetPartitionTable

Step 4:
Open SheetTable and delete the matched record with PartitionTable.

Automatically the matched record from SheetTable , PartititonTable and SheetPartitionTable will be deleted .

Wednesday, 17 September 2014

Virtual Company and Table Collection in AX 2012

Hi ,

Today i would like to share you how to create Virtual company and Table collection.

Step 1:

AOT----Data Dictionary ----Table collection----New Table Collection

Step 2:

Drag and Drop the Tables which you have decided to share

Example i have added PartitionTable(User Created Table)



Step 3:

Go to Administration -- Setup -- Virtual company accounts, and create a virtual company

Note: Before doing the above steps, make sure you are the Ax administrator and the only user online.

















Step 4:

Click Company Accounts Tab and select the Company which you have decided to access the Share Data















Step 5:

Click Table Collection Tab and Select the Table Collection















That's it Virtual Company is created.

Now your data will be available in Selected Company


Output:


TSC and LISP company are available Under Virtual Company.

Therefore the data's are display.

Note: DataAreaID for these data are VC





A&C company is not available under Virtual Company

Therefore data's are not displayed





Thursday, 4 September 2014

How to display Employee Image in Ax 2009 Report

Hi ,

Today i would like to share you how to display employee image in Ax 2009 report.

Step 1:

Attach Image to each Employee Record , using Document Handling Attachement

Go to Human Resource->Common Forms-> Employee Details

Step 2:

AOT->Reports->New Report

for an example , My Report name is EmployeeDetailsReport

Step 3:

Add EmplTable as Datasource to display Employee Details

Step 4 :

Write a display method with return type Bitmap to get the employee Image


 To Retrieve Employee Image from Document Handling

display Bitmap emplImage()
{
    Bitmap bitmap;
    Bindata binData = new BinData();
    Docuref docuref;
    Image image;
    ;
    select firstonly docuRef order by docuRef.modifiedDateTime desc where
        docuRef.RefCompanyId == curext() &&
        docuRef.RefRecId == EmplTable.RecId &&
        docuRef.RefTableId == EmplTable.TableId &&
        docuRef.TypeId == "Image";

    if (binData.loadFile(docuRef.completeFilename()))
    {
        bitmap = binData.getData();
    }

    return bitmap;
}

To retrieve Employee Name 

display Name EmplName()
{
;
return DirpartyTable::find(EmplTable.PartyId).Name;
}
Step 5:

Drag and Drop the emplname() and emplImage() method to design



Output:



Wednesday, 3 September 2014

How to create Number Sequence in Table Level in Ax 2009

Hi ,

Today i would like to share you how to create Number sequence in Table level in Ax 2009.

Step 1:

Create an EDT  SheetID

Step 2:

NumberSequenceReferences stores all the references and their corresponding numberseq codes

For an Example, create NumberSequence Reference under Accounts Payable Module

Go to AOT->Classes->NumberSeqReference_Vendor

Step 3:

Write a piece of code in loadmodule() of NumberSeqReference_Vendor class

    numRef.DataTypeId               = typeId2ExtendedTypeId(typeid(SheetId));
    numRef.ReferenceHelp            = literalstr("Unique key, allocated to a Presentation");
    numRef.WizardContinuous         = false;
    numRef.WizardManual             = NoYes::No;
    numRef.WizardAllowChangeDown    = NoYes::No;
    numRef.WizardAllowChangeUp      = NoYes::No;
    numRef.SortField                = 12;

    this.create(numRef);

Step 4:

Override the initValue() in Table (Eg:SheetTable)

public void initValue()
{
    NumberSeq       NumSeq;
    ;
    super();
    NumSeq =  NumberSeq::newGetNum(SheetTable::numRefSheetId(),true);
    this.SheetId = NumSeq.num();

}

create a new method to get NumRefID

public client server static NumberSequenceReference numRefSheetId()
{
    ;

    return NumberSeqReference::findReference(typeId2ExtendedTypeId(typeid(sheetId)));
}

Step 5:

Go to Basic->Setup->Number Sequence->Number sequence

Press Ctrl+N and create a new NumberSequenceCode

For an example i have created a code - KOR_123



Step 6:

Go to AccountPayable->Setup->Parameter
Click NumberSequence Tab


Output:

Happy Daxing...

How to change the Background Color for every form in Dyanmics AX

Hi ,

Today i would like to share you how to change the background color for every form in dynamics ax

Open SysSetupFormRun  Class in AOT, and override its run() with the following code:

public void run()
{;
 super();
 this.design().colorScheme(FormColorScheme::RGB);
 this.design().backgroundColor(WinAPI::RGB2int(255,0,0));
}
 
 
 
 

Tuesday, 2 September 2014

Sum of two Numbers using Dialog Class in Ax 2009

Hi ,

Today i would like to share you , how to get the dynamic input value using dialog class

In c, scanf() is used to get the dynamic input value .
Similarly in Ax , Dialog is used to get the dynamic input Value.

For an Example,

I wrote a class to get an input value from users dynamically and print the sum of values as output

Coding:

class Dynamicclass extends RunBase
{
    int FirstNum;
    int SecondNum;
    int SumValue;
   
    DialogGroup diaGrp;
    DialogField diaFld,diaFld2;
    Dialog      dialog;

}

Dialog:

protected Object dialog()
{
    ;

    dialog = super();

    dialog.caption("Enter the valid  Number");

    diaGrp=dialog.addGroup("Number");

    diaFld=dialog.addField(Typeid(Integer)," First Number","Enter the First Number");
    diaFld2=dialog.addField(Typeid(Integer)," Second Number","Enter the second Number");

    return dialog;
   
}

Display Date

void displaydata()
{
    ;
    info(strfmt("First Number =%1",FirstNum));
    info(strfmt("Second Number =%1",SecondNum));
    info(strfmt("Sum of Two Number =%1",SumValue));
}

Get Data:


void getdata(int _firstNum,int _secondNum)
{
    ;
   
    FirstNum    =   _firstNum;
    SecondNum   =   _secondNum;
    SumValue    =   _firstNum+_secondNum;
}

Pack:

public container pack()
{
    return connull();
}

Run:

void run()
{
    super();
   
    FirstNum = diaFld.value();
    SecondNum = diaFld2.value();
    this.getdata(FirstNum,SecondNum);
    this.displaydata();
}

UnPack:

public boolean unpack(container packedClass)
{
    return true;
}

Main:

public static void main(Args args)
{

Dynamicclass obj =new Dynamicclass();

    if(obj.prompt())
    {
         obj.run();
    }

}


Output:

Happy Daxing....

Grouping Field Value in Lookup in Ax 2009

Hi ,

Today i would like to share you how to group the field value in Lookup in Ax 2009

Example:
In Customer Table each Customer belongs to at-least one Customer Group.
For an example , Customer Group : India has three customer (Cust-001,cust-002 and cust-003)

Here is a piece of code , how to group the CustGroup Field from CustTable

Coding:
public void lookup()
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;

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

    sysTableLookup.addLookupfield(fieldNum(CustTable, CustGroup));
    queryBuildDataSource = query.addDataSource(tableNum(CustTable));

    queryBuildDataSource.addSortField(fieldnum(CustTable, CustGroup));
    queryBuildDataSource.addOrderByField(fieldnum(CustTable, CustGroup));
    queryBuildDataSource.orderMode(OrderMode::GroupBy);//Used to Group the Field Value

    sysTableLookup.parmQuery(query);
    SysTableLookup.parmUseLookupValue(false);
    sysTableLookup.performFormLookup();
}

Before Using Lookup Method

 After using Lookup Method


Happy Daxing.......

Saturday, 30 August 2014

Printing Barcode in AX 2009

Hi Guys,


I have gone through a wonderful blog where they have neatly explained how to display barcode in ax 2009 reports .
Click Here

Monday, 28 July 2014

How to filter the form from one Tabpage to another Tabpagen in AX

Hi,

Today I would like to share you how to filter the form from one Tab page to another Tab page .

For an Example i have two Tabpage in my Form
i)Accepted Sheet
ii)Rejected Sheet

When i click Accepted Sheet TabPage , the accepted sheet records must be shown.
Similar way if i click Rejected Sheet TabPage , the rejected sheet records must be listed.

Step 1:

Write the piece of code in the DataSource level executequery ()

public void executeQuery()
{

    this.Query().datasourceNo(1).clearRanges();
   
    if(AcceptedTabPge.isActivePage())
    {
        this.query().dataSourceName('SheetTable')
        .addRange(fieldnum(SheetTable,SheetAccepted)).value(queryvalue(NoYes::Yes));

    }
    if(RejectedTabPage.isActivePage())
    {
        this.query().dataSourceName('SheetTable')
        .addRange(fieldnum(SheetTable,SheetAccepted)).value(queryvalue(NoYes::No));
    }

    super();
   
}

Step 2:

write this piece of code in the pageactivated method of both Tabpage

public void pageActivated()
{
    super();
    SheetTable_ds.executeQuery();
}

Output:

TabPage 1:
 TabPage2:






Happy Daxing......

Sunday, 27 July 2014

How to add Search/ Find /Filter functionality to Display method in dynamics AX

Hi,

I have gone through a wonderful blog , where they have explained clearly how to add search/find/filter functionality to display method in dynamic AX

click here

Happy Daxing......

Dialog Events(Modified, lookups ) in AX 2009

Hi ,

Today i would like to share you how to do look-up filtration , modified method in dialog using dialog class

lookup :

void Fld5_1_lookup()
{
     Formrun                 fr = dialog.formRun();
    object                  Control = fr.controlCallingMethod();

    SysTableLookup          sysTableLookup =
    SysTableLookup::newParameters(tablenum(CEKMasterCostCardTable),  fieldMccId.fieldControl());
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    ;


    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, AccountNum),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Name),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Type),true);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, Active),false);
    sysTableLookup.addLookupfield(fieldnum(CEKMasterCostCardTable, MccId),false);


    queryBuildDataSource = query.addDataSource(tablenum(CEKMasterCostCardTable));
    queryBuildRange =         queryBuildDataSource.addRange(fieldnum(CEKMasterCostCardTable,AccountNum));
    queryBuildRange.value(queryvalue(fieldCustAccount.value()));


    sysTableLookup.parmQuery(query);
    sysTableLookup.parmUseLookupValue(false);
    sysTableLookup.performFormLookup();
}

modified :

public boolean Fld2_1_modified()

{
    FormCheckBoxControl control = dialog.formRun().controlCallingMethod();

    boolean isFieldModified;
    ;

    isFieldModified = control.modified();


    if(isFieldModified)
    {
        filedChkNewCard.value(0);
        fieldCustAccount.allowEdit(false);
        fieldMccId.allowEdit(false);
   
    }

    return isFieldModified;

}

dialog:

protected Object dialog()
{

    ;
    dialog = super();

    dialog.caption("Select  One of three below options or cancel");

    dialog.allowUpdateOnSelectCtrl(true);

   fieldChkBlankCard=dialog.addField(Typeid(NoYes),"Create New Blank Cost Card");
   fieldChkSelectedCard=dialog.addField(Typeid(NoYes),"Copy from selected "+cEKMasterCostCardTable.Name+','+cEKMasterCostCardTable.Type+','+cEKMasterCostCardTable.MccId);
   filedChkNewCard=dialog.addField(Typeid(NoYes),"Copy from Other Customer");

    fieldCustAccount    = dialog.addField(typeid(CustAccount)," Customer ID");
    fieldMccId = dialog.addField(typeid(CEKMccId),"MCC ID");
    fieldType=dialog.addField(typeid(str200),"Type");

    fieldText=dialog.addField(typeid(Notes));

    okButton = dialog.formBuildDesign().control('OKButton');

    okButton.enabled(false);

    return dialog;
}

dialogPostRun:

public void dialogPostRun(DialogRunbase  _dialog)
{
    super(_dialog);
    _dialog.dialogForm().formRun().controlMethodOverload(true);
    _dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}

pack:

public container pack()
{
    return connull();
}

unpack:

public boolean unpack(container packedClass)
{
    return true;
}

class delcaration:

class CEKMasterCostCardDialog extends RunBase
{
    DialogField fieldCustAccount;
    DialogField fieldMccId,fieldText,fieldType;
    DialogField fieldChkBlankCard,fieldChkSelectedCard,filedChkNewCard;
    FormBuildCommandButtonControl   okButton;
    CEKMasterCostCardTable cEKMasterCostCardTable;
    str Mcc;

    Dialog          dialog;

}
main:

public static void main(Args args)
{

    CEKMasterCostCardDialog cekMasterCostCardDialog;
    CEKMasterCostCardTable cekMasterCostCardTable;
    ;

    cekMasterCostCardDialog = new   CEKMasterCostCardDialog();

    if(cekMasterCostCardDialog.prompt())
    {
    cekMasterCostCardDialog.run();
    }

}

click here for the syntax in Dialog class.

click here  for detail explanation.


Happy daxing.....


Friday, 25 July 2014

Inserting Space between the characters in a String in Ax


Hi,

Today I would like to share you x++ code to insert space between the characters in a string in AX.

Example 1:

static void insertSpaceBtwString(Args _args)

{

str s,s1;

int i,j;

s="KORCOMPTENZ";

j= strLen(s);

for(i=1;i<=j;i++)

{

   s1=s1+subStr(s,i,1);

  if(i!=strLen(s))

  s1=s1+ " ";

}

info(s1);

}

Output:
 
 
 
Example 2:
 
Inserting space after each four digit Number
 

static void InsertSpace(Args _args)

{

str s,s1;

int i,j;

s="1245678945612355";

j= strLen(s);

for(i=1;i<=j;i=i+4)

{

    s1=s1+subStr(s,i,4);

    if(i+4<=j)

    s1=s1+" ";

}

info(s1);

}

Output:
 
 
 
 
 
Happy Daxing....


 

Wednesday, 9 July 2014

Valid Time State Tables in Dynamics AX 2012 [ValidTimeStateFieldType]


Hi Guys,

In DAX 2012, we can let the system manage data relationships that are valid only during a specified date range.
This can be achieved by setting “ValidTimeStateFieldType” property on the table.The system then adds the ValidFrom and ValidTo columns that track a date range in each row. The system guarantees that the values in these date fields remain valid by preventing overlap among date ranges, based on the primary key value.
Let me explain with an example. Let us create a new table with a new string field “Name” which extends Name EDT.
Right click on the table and set the ValidTimeStateFieldType property to utcdateTime as shown below

After setting this property, system will automatically create ValidFrom and ValidTo fields in your table as shown below

Create a new Index by name NameIdx and drag drop Name, ValidFrom, ValidTo fields on to the index and set the following properties on your newly created index as shown below.

You can set the NameIdx as replacement Key on the table.
Now open the table and start entering the data. you will notice that ValidTo will be automatically defaulted to maxdate() 12/31/2154[Never] and validFrom to system date and time now as shown below.



Happy Daxing....

X++ code to open the Excel as Read Only Mode


Hi Guys,

setFileAttribute method is used to open the file in read only mode , but mode value must be 1

Example:

filename= "C:\Users\chagirathi\Desktop\Master Cost Card Field Maping (1).xlsx";
Winapi::setFileAttributes(filename,1);

Happy Daxing....

X++ code to Count Records in Query


Hi Guys,

The below code is used to count records in query.


static void Query_cntRecords(Args _args)
{
    Query                query = new Query();
    QueryRun             queryRun;
    QueryBuildDataSource qbd;
   
    
    qbd = query.addDataSource(tablenum(CustTable));
    queryRun = new QueryRun(query);
   
    info(strfmt("Total Records in Query %1",SysQuery::countTotal(queryRun)));
   
}

Happy Daxing......

Removing Leading Zeros from a String

Hi Guys,

click here to get the X++ code "how to remove the leading Zeros from a sting in AX?"

Happy Daxing.....

Installation and configuration of EP in AX 2012 R2

Hi Guys,

Today I have referred a wonderful blog where they have neatly explained how to do installation and configuration of EP in AX 2012 R2.

click here

Happy Daxing......
 

Opening Google Webpage using ActiveX control in AX 2012 R3 Forms

Hi ,

Today i am going to share you , how to navigate to webpage using ActiveX control in AX 2012 R3 Form .

Step1:

Create New Form named as WebBrowserForm



Step 2:

Right click the Design node and select ActiveX


Step 3:

Select Microsoft Web Browser from AciveX window


Step 4:

Write some piece of code in init() method of the form

ActiveX.Navigate("www.google.com");

 
Output:

Thus Google page is displayed in AX Form.

Happy Daxing....


Saturday, 21 June 2014

Installation and Configuration of SSAS and SSRS in AX 2012

Hi Guys,

I have gone through a wonderful blog , where they have described about the SSAS, SSRS installation and configuration in AX 2012

click here for SSAS installation

click here for SSRS and SSAS installation

Happy Daxing.....

Saturday, 14 June 2014

Creating a New Sales order by copying existing Sales Order headers and lines in AX 2012

Hi Guys,

Today I am going to explain you , how to copy a existing sales order header and lines and create a new Sales Order.

Step 1:

Add two new control in Form level Design

1) SelectFromExistingSalesId (ControlType-CheckBox)
2)ExistingSalesId(ControlType-StingEdit)



Step 2:
Write a single line of code inside From Level init() method
ExistingSalesId.enabled(false);//Make the ExistingSalesId control Disable when the form open

Step 3:
write a piece of code inside SelectFromExistingSalesId checkbox Control modified() method




public boolean modified()
{
boolean ret;
ret = super();

if(SelectFromExisitngSalesId.value()==1)
{
   ExistingSalesId.enabled(true);
}
else
{
  ExistingSalesId.enabled(false);
}
return ret;

}
Step 4:
create a new method CreateSalesLines in the form level
 
 

public void createSalesLine(SalesId _salesId,ItemId _itemId)
{
SalesLine salesLine;
salesLine.clear();

salesLine.SalesId = _salesId;
salesLine.ItemId = _itemId;

salesLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes);
}

Step 5:
write a piece of code inside ExistingSalesId Control modified() method

 
public boolean modified()
{
SalesTable salesTableBuff;
SalesLine salesLineBuff;
ItemId existItemId;
SalesId currentSalesId;
SalesIdBase existSalesId;

boolean ret;
ret = super();

existSalesId=ExistingSalesId.valueStr();//Gets the Existing Sales Id

select firstOnly SalesId,CustAccount from salesTableBuff

where salesTableBuff.SalesId == existSalesId;

SalesTable.CustAccount = salesTableBuff.CustAccount;

currentSalesId= SalesTable.SalesId; //Gets the Newly generated Sales Id

SalesTable_ds.object(fieldNum(SalesTable,CustAccount)).modified();

SalesTable.insert();

while select ItemId from salesLineBuff where salesLineBuff.SalesId == existSalesId
{

   existItemId=salesLineBuff.ItemId;
   element.createSalesLine(currentSalesId, existItemId);

}

return ret;

}

Output:
 
A New Sales Oder is Created
 
 


That's it ........

Happy Daxing....



Passing Arguments from One Form to Another Form in AX 2012

Hi Guys,

Today I would like to share you how to pass arguments from one form to another form in AX 2012

Create Two New Table and Two New Form

For an example , I have created two new Table and two new Form

Table 1: SheetTable

 

Table 2:SheetDetails



Form 1 :SheetTable , Datasource Name : SheetTable

Create Ok Button in SheeTable Form


Write a piece of logic in the clicked method



void clicked()
{
Args args;
FormRun formRun;
super();
args = new args();
args.parm(SheetTable.SheetId);

args.record(SheetTable);
args.name( formstr( SheetDetails ) );

formRun = classFactory.formRunClass( Args );
formRun.init();
formrun.run();
formrun.wait();

}
Form 2: SheetDetails , DataSource Name : SheetDetails
 
 
write a piece of code in Form level init() method
public void init()
{
Query query;
QueryBuildRange qbr;
SheetTable _sheetTable;
SheetDetails sheetDetails1;
Str _parmid;
super();
_sheetTable = element.args().record();
_parmid= element.args().parm();
query= new Query();
qbr=query.addDataSource(tableNum(SheetDetails)).addRange(fieldNum(SheetDetails,SheetId));
qbr.value(_parmid);
SheetDetails_ds.query(query);
}
 
Output:
That's it ..........We have done it


Happy Daxing........