Hi All,
Here i written the code to use the Aggregate functions and Joins inDynamic Query in spite of using normal Select statement in Ax 2009
Normal Select Statement:
while select sum(qty) from inventTrans where inventTrans.ItemId == “OL-2500” join inventDimgroup by inventBatchId where inventDim.InventDimId == inventTrans.InventDimId
{
// Our Code Here
}
Dynamic Query:
static void Vasanth_Query_Eg1(Args _args)
{
Query query;
QueryBuildDataSource queryBuildDataSource;
QueryBuildRange queryBuildRange;
QueryRun queryRun;
Qty total;
InventTrans inventTrans;
;
query = new Query(); queryBuildDataSource = query.addDataSource(tableNum(InventTrans));
queryBuildDataSource.addSelectionField(fieldNum(InventTrans,Qty),
SelectionField::Sum);
queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildRange = queryBuildDataSource.addRange(fieldNum(InventTrans,ItemId));
queryBuildDataSource = queryBuildDataSource.addDataSource(tableNum(InventDim));
queryBuildDataSource.orderMode(OrderMode::GroupBy);
queryBuildDataSource.addSortField(fieldNum(InventDim,InventBatchId));
queryBuildDataSource.relations(true);
queryRun = new QueryRun(query);
if (queryRun.prompt())
{
while (queryRun.next())
{
inventTrans = queryRun.get(tableNum(InventTrans));
total = inventTrans.Qty;
}
}
info(strFmt(“Quantity: %1″, total));
}
Tuesday, April 16, 2013
RegularExpression in Axapta
Hi All,
Here i posted a small job , to explain how we use regular expressin in Axapta. Try it.
static void RegularExpression_Test()
{
int nameLength,myStringLength;
str myname = “Ashok”;
str myString = “1234″;
str formatString , formatString1;
System.Text.RegularExpressions.Regex regEx;
System.Text.RegularExpressions.Regex regEx1;
System.Text.RegularExpressions.Match regMatch;
InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
boolean retVal, retVal1;
;
nameLength = strLen(myname);
myStringLength = strLen(myString);
formatString = strfmt(@”^[0-9]{%1}”, myStringLength);
formatString1 = strfmt(@”^[a-zA-Z ]{%1}”, nameLength);
permission.assert();
//BP Deviation documented
regEx = new System.Text.RegularExpression.Regex(formatString);
regEx1 = new System.Text.RegularExpression.Regex(formatString1);
regMatch = regEx.Match(myString);
retVal = regMatch.get_Success();
print retVal; // Returns True;
regMatch = regEx1.Match(myname);
retVal1 = regMatch.get_Success();
print retVal1 // Returns True;
}
Here i posted a small job , to explain how we use regular expressin in Axapta. Try it.
static void RegularExpression_Test()
{
int nameLength,myStringLength;
str myname = “Ashok”;
str myString = “1234″;
str formatString , formatString1;
System.Text.RegularExpressions.Regex regEx;
System.Text.RegularExpressions.Regex regEx1;
System.Text.RegularExpressions.Match regMatch;
InteropPermission permission = new InteropPermission(InteropKind::ClrInterop);
boolean retVal, retVal1;
;
nameLength = strLen(myname);
myStringLength = strLen(myString);
formatString = strfmt(@”^[0-9]{%1}”, myStringLength);
formatString1 = strfmt(@”^[a-zA-Z ]{%1}”, nameLength);
permission.assert();
//BP Deviation documented
regEx = new System.Text.RegularExpression.Regex(formatString);
regEx1 = new System.Text.RegularExpression.Regex(formatString1);
regMatch = regEx.Match(myString);
retVal = regMatch.get_Success();
print retVal; // Returns True;
regMatch = regEx1.Match(myname);
retVal1 = regMatch.get_Success();
print retVal1 // Returns True;
}
“Go To Main Table” Option in our Axapta
Hi All,
We all know about “Go To Main Table” Option in our Axapta Forms and Tables. Here I wrote one sample for how to get that functionality in our forms or table. This is done by three ways:
1) By EDT Relations
2) By using JumpRef method
3) By using FormRef property in Table
EDT Relations:
If you use an EDT in tables which have relation with some other table fileds, that time you can able to navigate the main table or main form.
FormRef Property:
Select the Table and go to properties and select the required form in the FormRef property.
JumpRef method:
If you are not having that option, simply write a override the JumpRef method in a field of DataSource or in a Form Control. Here i show you a sample jumpRef method code:
public void jumpRef()
{
Args args;
MenuFunction menuFunction;
;
args = new Args();
menuFunction = new MenuFunction(menuitemDisplayStr(“FormName”), MenuItemType::Display);
args = new Args(menuFunction.object());
args.caller(element);
args.record(“RecordName”); // to be a datasource which added in the current form
menuFunction.run(args);
}
In the form init() which we called here, we have to check the condition whether the form is called by any dataset or not.................!!!
We all know about “Go To Main Table” Option in our Axapta Forms and Tables. Here I wrote one sample for how to get that functionality in our forms or table. This is done by three ways:
1) By EDT Relations
2) By using JumpRef method
3) By using FormRef property in Table
EDT Relations:
If you use an EDT in tables which have relation with some other table fileds, that time you can able to navigate the main table or main form.
FormRef Property:
Select the Table and go to properties and select the required form in the FormRef property.
JumpRef method:
If you are not having that option, simply write a override the JumpRef method in a field of DataSource or in a Form Control. Here i show you a sample jumpRef method code:
public void jumpRef()
{
Args args;
MenuFunction menuFunction;
;
args = new Args();
menuFunction = new MenuFunction(menuitemDisplayStr(“FormName”), MenuItemType::Display);
args = new Args(menuFunction.object());
args.caller(element);
args.record(“RecordName”); // to be a datasource which added in the current form
menuFunction.run(args);
}
In the form init() which we called here, we have to check the condition whether the form is called by any dataset or not.................!!!
Friday, October 5, 2012
Changing numerals to text in Indian Format amount in words India
Changing numerals to text in Indian Format
static TempStr numerals2Txt_IN(real _num)
{
int numOfPennies = (decround(frac(_num), 2) * 100) mod 100;
real test = _num - frac(_num);
int numOfTenths;
str 20 ones[19], tenths[9], hundreds, thousands, lakhs, crores;
int64 temp;
str 200 returntxt;
str 200 pennytxt;
int penny;
real modOperator(real a1, real a2)
{
int tmpi;
real tmp1, tmp2;
tmp1 = a1 / a2;
tmpi = real2int(tmp1);
tmp2 = tmpi;
return (tmp1 - tmp2)*a2;
}
real checkPower(real _test, int64 _power)
{
int64 numOfPower;
if (_test >= _power)
{
numOfPower = _test div _power;
if (numOfPower >= 100)
{
temp = numOfPower div 100;
returntxt = returntxt + ' ' + ones[temp] + ' ' + hundreds;
numOfPower = numOfPower mod 100;
}
if (numOfPower >= 20)
{
temp = numOfPower div 10;
returntxt = returntxt + ' ' + tenths[temp];
numOfPower = numOfPower mod 10;
}
if (numOfPower >= 1)
{
returntxt = returntxt + ' ' + ones[numOfPower];
numOfPower = numOfPower mod 10;
}
switch(_power)
{
case 10000000 :
{
returntxt = returntxt + ' ' + Crores;
_test = modOperator(_test, 10000000);
break;
}
case 100000 :
{
returntxt = returntxt + ' ' + lakhs;
_test = modOperator(_test, 100000);
break;
}
case 1000 :
{
returntxt = returntxt + ' ' + thousands;
_test = modOperator(_test, 1000);
break;
}
case 100 :
{
returntxt = returntxt + ' ' + hundreds;
_test = modOperator(_test, 100);
break;
}
}
}
return _test;
}
#Define.text_1('One')
#Define.text_2('Two')
#Define.text_3('Three')
#Define.text_4('Four')
#Define.text_5('Five')
#Define.text_6('Six')
#Define.text_7('Seven')
#Define.text_8('Eight')
#Define.text_9('Nine')
#Define.text_10('Ten')
#Define.text_11('Eleven')
#Define.text_12('Twelve')
#Define.text_13('Thirteen')
#Define.text_14('Fourteen')
#Define.text_15('Fifteen')
#Define.text_16('Sixteen')
#Define.text_17('Seventeen')
#Define.text_18('Eighteen')
#Define.text_19('Nineteen')
#Define.text_20('Twenty')
#Define.text_30('Thirty')
#Define.text_40('Forty')
#Define.text_50('Fifty')
#Define.text_60('Sixty')
#Define.text_70('Seventy')
#Define.text_80('Eighty')
#Define.text_90('Ninety')
#Define.text_100('Hundred')
#Define.text_1000('Thousand')
#Define.text_100000('Lakh')
#Define.text_10000000('Crore')
#Define.text_and('Rupees and')
#Define.text_paise('Paise Only')
#Define.text_ruppe('Rupees Only')
ones[1] = #text_1;
ones[2] = #text_2;
ones[3] = #text_3;
ones[4] = #text_4;
ones[5] = #text_5;
ones[6] = #text_6;
ones[7] = #text_7;
ones[8] = #text_8;
ones[9] = #text_9;
ones[10] = #text_10;
ones[11] = #text_11;
ones[12] = #text_12;
ones[13] = #text_13;
ones[14] = #text_14;
ones[15] = #text_15;
ones[16] = #text_16;
ones[17] = #text_17;
ones[18] = #text_18;
ones[19] = #text_19;
tenths[1] = 'Not used';
tenths[2] = #text_20;
tenths[3] = #text_30;
tenths[4] = #text_40;
tenths[5] = #text_50;
tenths[6] = #text_60;
tenths[7] = #text_70;
tenths[8] = #text_80;
tenths[9] = #text_90;
hundreds = #text_100;
thousands = #text_1000;
lakhs = #text_100000;
crores = #text_10000000;
test = checkPower(test, 10000000);
test = checkPower(test, 100000);
test = checkPower(test, 1000);
test = checkPower(test, 100);
if (test >= 20)
{
numOfTenths = test div 10;
returntxt = returntxt + ' ' + tenths[numofTenths];
numOfTenths = numOfTenths mod 10;
test = test mod 10;
}
if (test >= 1)
{
numOfTenths = real2int(test);
returntxt = returntxt + ' ' + ones[numOfTenths];
}
if (numOfPennies)
{
if (numOfPennies >= 20)
{
penny = numOfPennies div 10;
pennytxt = tenths[penny];
numOfPennies = numOfPennies mod 10;
}
if (numOfPennies >= 1)
{
pennytxt = pennytxt + ' ' + ones[numOfPennies];
}
returntxt = returntxt + ' ' + #text_and + ' ' + pennytxt + ' ' +#text_paise;
}
else
{
returntxt = returntxt + ' ' + #text_ruppe;
}
return returntxt;
}
Tuesday, September 4, 2012
Get day, month and year from date in axapta x++
Get day, month and year from date in axapta x++
Hi, everybody!
In Dynamics AX, sometimes we need to get the day, month or year from a date and we don't know how to do this... but we can do this easily...
//Get day from date
dayOfMth(systemdateget())
//Get month from date
mthOfYr(systemdateget())
//Get year from date
year(systemdateget())
Good DaXing!
Hi, everybody!
In Dynamics AX, sometimes we need to get the day, month or year from a date and we don't know how to do this... but we can do this easily...
//Get day from date
dayOfMth(systemdateget())
//Get month from date
mthOfYr(systemdateget())
//Get year from date
year(systemdateget())
Good DaXing!
Friday, August 31, 2012
Cross-company Support In Ax2012
Cross-company Support
Microsoft Dynamics AX can have multiple companies in one data base. Ex: container conCompanies = [ 'cee', 'ceu' ]; custTable custTable;
while select crossCompany : conCompanies custTable
{
print custTable.accountNum;
}
pause;
Microsoft Dynamics AX can have multiple companies in one data base. Ex: container conCompanies = [ 'cee', 'ceu' ]; custTable custTable;
while select crossCompany : conCompanies custTable
{
print custTable.accountNum;
}
pause;
Eventing In Ax2012
Eventing
Lets the user use a publisher and subscriber model when modifying MDAX2012.
Events can be modeled in the AOT or be used as a programming construct and can be handled in either X++ code or in managed code.
NOTE: Modeled events are only available on classes and not tables or forms.
Eventing Terminology
MDAX2012 events are modeled after the .NET event concepts :
Producer :- The producer is the logic that contains the code that causes a change. This means that it is the entity that emits events.
Consumer :- The consumer is the application code that manifested an interest in being notified when a specific event occurs. This means that it is an entity that receives events.
Event :- An event is a representation of a change that happened in the producer. Microsoft Dynamics AX 6.0 supports Pre and Post events that occur before and after a method is called.
Event Payload :- The event payload is the information that the event carries with it. If a person is hired, for example, the payload includes the employee's name and date of birth, and so on.
Delegate :- A delegate is the definition of the information passed from the producer to the consumer when an event happens.
Event Handlers
Event handlers are methods that are called when the delegate is called, directly through code (for the coded events) or from the environment (in the modeled events). The relationship between the delegate and the handlers can be maintained in code or in the AOT.
Delegate is a keyword.
When program conditions meet the programmer's criteria for the event, the X++ code can call the delegate, and that causes the delegate to call all the event handler methods that are added to the delegate.
To create a delegate, right-click the class and select New->Delegate.
Adding Handlers in the AOT
The user must identify a static method to handle the event on the delegate. However, when adding event handlers from code, described in the following material, instance methods are also applicable as event handlers. Event handlers can be added to the delegate by dragging the event handler to the delegate node that represents the event to be handled.
Adding Handlers in Code
Use special X++ syntax to remove or add event handlers to events. The delegate name appears on the left side of the += operator.
private void AddStaticHandler()
{
;
this.MyDelegate += eventhandler
(Subscriber::MyHandler);
}
Pre and Post Events
You can subscribe an event handler to automatically run immediately before a method is run.
The event handler can change the parameter values before they are entered into the method. You can also subscribe an event handler to run immediately after a method is run. The event handler can change the value that is returned by the method, before the return value is received by the caller of the method.
Event handlers for these before and after events are visible in the AOT as sub nodes on the methods to which they apply.
Lets the user use a publisher and subscriber model when modifying MDAX2012.
Events can be modeled in the AOT or be used as a programming construct and can be handled in either X++ code or in managed code.
NOTE: Modeled events are only available on classes and not tables or forms.
Eventing Terminology
MDAX2012 events are modeled after the .NET event concepts :
Producer :- The producer is the logic that contains the code that causes a change. This means that it is the entity that emits events.
Consumer :- The consumer is the application code that manifested an interest in being notified when a specific event occurs. This means that it is an entity that receives events.
Event :- An event is a representation of a change that happened in the producer. Microsoft Dynamics AX 6.0 supports Pre and Post events that occur before and after a method is called.
Event Payload :- The event payload is the information that the event carries with it. If a person is hired, for example, the payload includes the employee's name and date of birth, and so on.
Delegate :- A delegate is the definition of the information passed from the producer to the consumer when an event happens.
Event Handlers
Event handlers are methods that are called when the delegate is called, directly through code (for the coded events) or from the environment (in the modeled events). The relationship between the delegate and the handlers can be maintained in code or in the AOT.
Delegate is a keyword.
When program conditions meet the programmer's criteria for the event, the X++ code can call the delegate, and that causes the delegate to call all the event handler methods that are added to the delegate.
To create a delegate, right-click the class and select New->Delegate.
Adding Handlers in the AOT
The user must identify a static method to handle the event on the delegate. However, when adding event handlers from code, described in the following material, instance methods are also applicable as event handlers. Event handlers can be added to the delegate by dragging the event handler to the delegate node that represents the event to be handled.
Adding Handlers in Code
Use special X++ syntax to remove or add event handlers to events. The delegate name appears on the left side of the += operator.
private void AddStaticHandler()
{
;
this.MyDelegate += eventhandler
(Subscriber::MyHandler);
}
Pre and Post Events
You can subscribe an event handler to automatically run immediately before a method is run.
The event handler can change the parameter values before they are entered into the method. You can also subscribe an event handler to run immediately after a method is run. The event handler can change the value that is returned by the method, before the return value is received by the caller of the method.
Event handlers for these before and after events are visible in the AOT as sub nodes on the methods to which they apply.
Subscribe to:
Posts (Atom)
