Sunday, 21 September 2014

Retrieving The Online Application Users

Retrieving The Online Application Users

Using the following code we can retrieve the online application users list


static void onlineusers(Args _args)
{
sysclientsessions s;
;

while select s
where s.Status == NoYes::Yes
{
info(s.userId);
}
}

Compile and run the code,,,,,,,,,,,,,,,,,,,


IP Address Retrieval


                                     Retrieving The current IP addresses

The folliowing code explains how to retrieve the IP adddesses that used to acces the network


static void retrieveip(Args _args)
{
System.String hostName = System.Net.Dns::GetHostName();
System.Net.IPHostEntry hostEntry = System.Net.Dns::GetHostEntry(hostName);
System.Net.IPAddress[] addresses = hostEntry.get_AddressList();
System.Net.IPAddress address;
System.Net.Sockets.AddressFamily addressFamily;
System.Collections.IEnumerator enumerator = addresses.GetEnumerator();

while (enumerator.MoveNext())
{
address = enumerator.get_Current();
addressFamily = address.get_AddressFamily();
if (addressFamily == System.Net.Sockets.AddressFamily::InterNetwork)
{
info(address.ToString());
}
}
}


compile and run the code ,,,,,,,,,,,,,,,,,

Friday, 19 September 2014

Getting The Screen Resolution in AX

                                               Getting The Screen Resolution in AX


To get the screen Resolution we can write a job in AX,,,,,,,,,,,,,,,,,,,,,

static void ResolnMetrics(Args _args)
{
#WinAPI
int screenWidth, screenHeight;
;
screenWidth = WinAPI::getSystemMetrics(#SM_CXSCREEN);
screenHeight = WinAPI::getSystemMetrics(#SM_CYSCREEN);
info(strfmt("Screen resolution: %1 x %2",screenWidth, screenHeight));

}

Run the job and see............................!!!!!!!!!!!!



The Screen resolution is  1280*720                                                                                                           



CURRENCY CONVERSION IN AX 2012

                                           CONVERSION OF CURRENCY

To convert the currency to standard USD |From any other Currency like EUR,INR etc......

Try the following code in a job.

static void SrchCurrncy(Args _args)
{
CurrencyExchangeHelper currencyExchangeHelper;
CurrencyCode transCurrency = 'INR'; // try with EUR also
AmountCur amountCur = 600.00;
AmountMst amountMST;

currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
info(strFmt("%1",amountMST));

}


Now run the code and see........... 



 The  Rs600 =$11.35  only.... !!!!!!!!!!!!!!!!!!!!!!!!!!!

Creation of a Form using X++ code

                                 Creation of a Form using X++ code

To write an X++ job to create a basic form with a Tab page and inside a grid having two contols and we are taking PurchTable as Datasourse.

Job:

static void FormCreation(Args _args)
{
Form form;
FormRun formRun;
Args args;
FormBuildDesign formBuildDesign;
FormBuildControl formBuildControl;
FormBuildTabControl formBuildTabControl;
FormBuildTabPageControl formBuildTabPageControl;
FormBuildGridControl formBuildGridControl;
FormBuildDatasource formBuildDatasource;
FormBuildStringControl formString1;
;

form = new Form();

formBuildDatasource = form.addDataSource(tableStr(PurchTable));
formBuildDesign = form.addDesign("design");

formBuildTabControl = formBuildDesign.addControl(FormControlType::Tab, "Tab");
formBuildTabPageControl = formBuildTabControl.addControl(FormControlType::TabPage, "TabPage1");

formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::Grid, "Grid");
formString1 = formBuildGridControl.addDataField(formBuildDatasource.id(), fieldNum(PurchTable, PurchId));

formString1.label("PurchIds");
formString1 = formBuildGridControl.addControl(FormControlType::Real,"albion");

formString1.label("RaelValue");

args = new Args();
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}



Run the job and see................... the following form





Thursday, 18 September 2014

Retrieving The Address,State and Country Region id of a Vendor

Retrieving the address,state and country region id of purticular vendor whose “Purpose” is “Business”.

Scenario: To write a job to retrieve the address,state and cuontry region id of purticular vendor whose “Purpose” is Bussiness.

Step1

AP-->common-->vendors-->all vendors . Select a purticular vendor , select the Business address and give Edit . In the Address part you can see the State and country region id also. Now you have to write a job to fetch all these details for the selected the Business address.


Step2
write the job

static void retrievingcountry(Args _args)
{
VendTable vendTable;
LogisticsPostalAddress logisticsPostalAddress;
str aa;
str address;
str country;
str state;
vendTable = VendTable::find("JP-001");
address = DirParty::getPostalAddressByType(vendTable.Party,LogisticsLocationRoleType::Business);
while select logisticsPostalAddress
if (logisticsPostalAddress.Address == address)
{
info(logisticsPostalAddress.CountryRegionId);
info(logisticsPostalAddress.State);
info(logisticsPostalAddress.Address);
}
}

run the job


Monday, 15 September 2014

Sales Comparison between an Year and Previous Years Based on Quantity Ordered

Sales Comparison between an Year and Previous Years Based on Quantity Ordered

Compare the SalesQty of an year with the previous year Qty.

So that create a Form with fields item id,name,QtyOrdered,QtyOrderedPrv1,QtyOrderedPrv2, QtyOrderedPrv3.

Add two controls “Month” and “Year”. Month should show month lookup and Year should show a lookup of , years from 2011-2014.

When you are selecting a month and year in the two controls , it should show the Selected Year's month's Qty ordered and previous year's same month's Qty Ordered.


Step1

Creat a new table with fields item id,name,QtyOrdered,QtyOrderedPrv1,QtyOrderedPrv2, QtyOrderedPrv3.



Make it as a temporary table by giving “TableType:In memory”

Step2

Add the table as a new form's data sourse and add all the fields to a new Group-->Grid

Add another Group and add two combo boxes Month and Year

Under a ButtonGroup create an OK button





Step3

Month combo box cotrol's lookup can be done by assigning the property “EnumType : MonthsOfYeaR”.

For year lookup no EDT look up is available.So use a custom look by wrting the following code in “init()” method of the form.

public void init()
{
int i,curyear;
;
super();
for(i=0;i<5;i++)
{
curyear = 2010+i;
yearcomb.insert(int2str(curyear),i);
}
}

Step4
Get SalesQty,name and item id, for the selected year and month into respective fields QtyOrdered, item id,name in the temporary table


Then get the Previous Yerars's only SalesQty for first selected itemid and name(check “group by” in program) and assign them to QtyOrderedPrv1,QtyOrderedPrv2, QtyOrderedPrv3 in the temporary table.

For the above purposes write the following codes

1) under Form level methods

SalesLineTab populateRecords(date startDate,date endDate)
{
SalesLine s1;
SalesLineTab s2;
InventTable i1;
int i2;

while select i1

{
while select sum(QtyOrdered) from s1 group by ItemId,Name
where s1.ItemId == i1.ItemId
&& (s1.ConfirmedDlv >= startDate && s1.ConfirmedDlv <= endDate)

{
s2.ItemId = s1.ItemId;
s2.Name = s1.Name;
s2.QtyOrdered = s1.QtyOrdered;
s2.insert();
}
}


ttsBegin;
for(i2=0;i2<3;i2++)
{
startDate = prevYr(startDate);
endDate = prevYr(endDate);


while select forupdate s2
{

while select sum(QtyOrdered) from s1
where s1.ItemId == s2.ItemId
&& (s1.ConfirmedDlv >= startDate && s1.ConfirmedDlv <= endDate)
{
if(i2==0)
s2.QtyOrderedPrv1=s1.QtyOrdered;
if(i2==1)
s2.QtyOrderedPrv2=s1.QtyOrdered;
if(i2==2)
s2.QtyOrderedPrv3=s1.QtyOrdered;
s2.update();
}

}
}
ttsCommit;


return s2;

2.under clicked() method of the OK button[ to create startDate and endDate ]

void clicked()
{
int b,y;
date startDate1, endDate1;

switch(MonthEnum.selection())
{
case MonthEnum.selection()==MonthsOfYear::January:
b = enum2int(MonthsOfYear::January);
break;

case MonthsOfYear::February:
b = enum2int(MonthsOfYear::February);
break;

case MonthsOfYear::March:
b = enum2int(MonthsOfYear::March);
break;

case MonthsOfYear::April:
b = enum2int(MonthsOfYear::April);
break;

case MonthsOfYear::May:
b = enum2int(MonthsOfYear::May);
break;

case MonthsOfYear::June:
b = enum2int(MonthsOfYear::June);
break;

case MonthsOfYear::July:
b = enum2int(MonthsOfYear::July);
break;

case MonthsOfYear::August:
b = enum2int(MonthsOfYear::August);
break;

case MonthsOfYear::September:
b = enum2int(MonthsOfYear::September);
break;

case MonthsOfYear::October:
b = enum2int(MonthsOfYear::October);
break;

case MonthsOfYear::November:
b = enum2int(MonthsOfYear::November);
break;

case MonthsOfYear::December:
b = enum2int(MonthsOfYear::December);
break;
}
y = str2int(YearComb.valueStr());

startDate1 = mkDate(1,b,y) ;
endDate1 = mkDate(31,b,y);
super();

SalesLineTab.setTmpData(element.populateRecords(startDate1,endDate1)); // to populate the records that updated to the temporay table at run time
SalesLineTab_ds.executeQuery(); // refresh the data souese

}

Step5

Now you open the form and select the year(2014) and month(january) from lookups and Click the Ok button


Now see the form...

Friday, 12 September 2014

Adding All The TransferLines of a TranferOrder at a time Using a Button

Importing and Adding all the TransferLines for a TransferOrder at a time using a Button, From a “.CSV” file 

The requirement is that, instead of adding each TransferLine separately , add all the TransferLines from a .CSV, at time by clicking a button in TransferLine form for Single TransferOrder


Step1:

a)*Go to  USMF--Inventory Management—Periodic—TranferOrders, open the form

*check what are the tables and form used for the the TransferOrder and Line

                            1.InventTransferOrderTable
                            2.InventTransferLine
                            3.InventTransferOrder----form
b) [Create a CSV file with some dummy data as same as in the Line form (or) refer           axbeginners.blogspot.in ]



Step2

*Add a button(Excel) in the action pane of the Line form

*Under clicked() method of this button , we have to write the logic, to import and add all the
Lines at a time

[when ever you are clicking the button ,it should open a dialog form where we can mention the path of the Csv file]

*write the code under button




void clicked()
{

Dialog dialog;
DialogField dialogFileName;
SysOperationProgress simpleProgress;
Filename filename;
FileIOPermission permission;
TextIO textIO;

#define.ShipDate("1/1/2014")
#define.ReceiveDate("1/1/2014")
#define.Site("1")
#define.Warehouse("11")


InventTransferTable inventTransferTable1;
InventTransferLine inventTransferLine1;
InventDim inventDim1;


str s11;
int i;
Container c1;
CompanyInfo companyInfoLoc = CompanyInfo::find();
Container filterCriteria;
#File
#avifiles
;

super();

dialog = new Dialog("Importing Text File");
dialogFileName = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
filterCriteria = ['*.txt'];
filterCriteria = dialog.filenameLookupFilter(filterCriteria);
dialog.run();
if (dialog.run())
filename = dialogFileName.value();
if(!filename)
{
info("Filename must be filled");
}
permission = new fileIOpermission(filename,#io_read);
permission.assert();
textIO = new TextIO(filename,#io_read);
textIO.inFieldDelimiter(',');///Change the Delimeter if it is , or ; etc
simpleProgress = SysOperationProgress::newGeneral(#aviUpdate, 'Importing sales data',100);
if(textIO)
{
while(textIO.status() == IO_Status::Ok)
{
c1 = textIO.read();
s11 = conpeek(c1,1);
if(strlen(s11) > 1)
{


try
{
ttsbegin;

if (inventTransferTable.validateWrite())
{


// to gnererate all the Order lines
inventDim.clear();
inventDim.InventSiteId = "1";
inventDim.InventLocationId = "12";
inventDim.InventLocationId = Conpeek(c1,2);

inventTransferLine.clear();
inventTransferLine.initValue();

inventTransferLine.ItemId = Conpeek(c1,1);
inventTransferLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
inventTransferLine.QtyTransfer = Conpeek(c1,3);

inventTransferLine.initFromInventTableModule(InventTableModule::find
(inventTransferLine.ItemId,ModuleInventPurchSales::Invent));

inventTransferLine.QtyRemainReceive = inventTransferLine.QtyTransfer;
inventTransferLine.QtyRemainShip = inventTransferLine.QtyTransfer;

inventTransferLine.ShipDate = str2Date(#ShipDate, 213);
inventTransferLine.ReceiveDate = str2Date(#ReceiveDate, 213);


inventTransferLine.initFromInventTransferTable(inventTransferTable, false);
inventTransferLine.LineNum = InventTransferLine::lastLineNum
(inventTransferLine.TransferId) + 1.0;

if (inventTransferLine.validateWrite())
{
inventTransferLine.insert();
}
else
throw error("Order line");
}


ttscommit;
}
catch
{
error("Error!");
return;
}

info("Done!");
}

i++;
simpleProgress.incCount();
simpleprogress.setText(strfmt("Lines imported: %1", i));
sleep(10);
}
}
}

Step4

Again go to  USMF--Inventory Management—Periodic—TranferOrders, open the form. then create a new Transfer order and click the button

[Choose the path of the CSV file in dialodg form and give OK [Create a CSV file with some dummy data as same as in the Line form ]

Now all the transferLines will be added for the transferOrder