static void DateTime(Args _args)
{
UtcDateTime dateTime;
;
dateTime = DateTimeUtil::newDateTime(systemdateget(),DateTimeUtil::time(DateTimeUtil::getSystemDateTime()));
info(datetime2str(dateTime));
}
This blog is for Dynamics AX (AXAPTA) Developers,this will help you for your development issues. This site contains some Microsoft Dynamics AX X++ Codes for use in your day to day use.
21 February 2013
08 February 2013
X++ code to open a form or menuitem AXAPTA
how to open a form by using x++ code:
static void OpenDisplayMenuItem()
{
Args args = new Args();
;
args.record(VendTable::find("XYZ"));
new MenuFunction(MenuItemDisplayStr(VendTable),MenuItemType::Display).run(Args);
}
------
static void OpenForm()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(VendTable));
args.record(CustTable::find("XYZ"));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
static void OpenDisplayMenuItem()
{
Args args = new Args();
;
args.record(VendTable::find("XYZ"));
new MenuFunction(MenuItemDisplayStr(VendTable),MenuItemType::Display).run(Args);
}
------
static void OpenForm()
{ FormRun formRun;
Args args = new Args();
;
args.name(formstr(VendTable));
args.record(CustTable::find("XYZ"));
formRun = ClassFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait();
}
07 February 2013
like operator in Axapta
To get matching words in query
static void Job587(Args _args)
{
CustTable custTable;
select custTable where custTable.Name like("*john*");// match with john
select custTable where custTable.Name like("*john");// end with with john
select custTable where custTable.Name like("john*");// start with john
info(custTable.Name);
}
static void Job587(Args _args)
{
CustTable custTable;
select custTable where custTable.Name like("*john*");// match with john
select custTable where custTable.Name like("*john");// end with with john
select custTable where custTable.Name like("john*");// start with john
info(custTable.Name);
}
Cannot edit a record in Sales orders (SalesTable). An update conflict occurred due to another user process deleting the record or changing one or more fields in the record.
ttsbegin;
salesTable.reread() /* <--Have to call before update a record*/
if(salesTable.recid)
{
salesTable.update()
}
ttscommit;
02 February 2013
Calling the manu item name in form initiation
Calling the manu item name in form initiation
Form init method()
element.args().menuItemName() == menuitemDisplayStr(GPI_CopyProduct)
31 January 2013
Exception handling in AX / Try catch throw in AX
public boolean createExcelApp()
{
boolean ret = true;
;
try
{
sysExcelApplication = SysExcelApplication::construct();
if (sysExcelApplication == null)
{
ret = false;
throw Exception::Error;
}
}
catch (Exception::Error)
{
error("@SYS59928");
}
return ret;
}
{
boolean ret = true;
;
try
{
sysExcelApplication = SysExcelApplication::construct();
if (sysExcelApplication == null)
{
ret = false;
throw Exception::Error;
}
}
catch (Exception::Error)
{
error("@SYS59928");
}
return ret;
}
=============UPdate exception=========
System.Exception ex;
try
{
tableBuffer.field = value;
tableBuffer.update();
}
catch(ex)
{
System.String messageEx = ex.Message;
errorMessage = messageEx;
}
30 January 2013
Dialog in class with batch job in AX/ working with batch job in AX
1. Class have to extend the RunbaseBatch
2. implement the Run() in this method we can call our method which is created for logic(upload()).
3. Implement the pack and unpack methods
4. Implement the dialog() method
5. Construct() method
6. getFromDialog() method
7. Main method
8. Description method
9. Validate method
10.canGoBatch()
11.canGoBatchJournal
--
class INU_UpdExtProcComplete extends runbasebatch
{
DialogField dlgField;
FilenameOpen filenameOpen;
#define.CurrentVersion(1)
#define.Version(1)
#localmacro.CurrentList
filenameOpen
#endmacro
}
--
public void run()
{
if(filenameOpen)
{
if(WINAPI::fileExists(filenameOpen))
this.upload();
else throw error("@SYS26757");
}
super();
}
--
client static INU_UpdExtProcComplete construct()
{
return new INU_UpdExtProcComplete();
}
--
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
--
public boolean unpack(container packedClass)
{
Version version = Runbase::getVersion(packedClass);
switch(version)
{
case #CurrentVersion:
[version, #CurrentList] = packedClass;
break;
default:
return false;
}
return true;
}
--
public boolean getFromDialog()
{
boolean ret;
ret = super();
filenameOpen = dlgField.value();
return ret;
}
--
public Object dialog()
{
DialogRunbase dialog = super();
;
dlgField = dialog.addFieldValue(typeid(FilenameOpen),"","@IST10755","@IST10755");
return dialog;
}
--
void upload()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
FileName filename;
TINS_PurchTable tINS_PurchTable;
PurchId purchId;
str dataArea;
;
row++;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
filename = filenameOpen;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("@SYS19358");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
purchId = cells.item(row, 1).value().bStr();
dataArea = cells.item(row, 2).value().bStr();
if(purchId)
{
ttsbegin;
select forupdate crosscompany purchTable
where purchTable.PurchId == purchId;
if(tINS_PurchTable.PurchId)
{
changecompany(dataArea)
{
purchTable.OneTimeVendor = Noyes::Yes;
purchTable.doupdate();
info("The purchase id %1 is updated successfully",purchTable.PurchId);
}
}
else
{
info(strfmt("@IST10757",purchId));
}
ttscommit;
}
else
{
throw error(strfmt("@IST10758"));
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
--
public static void main(Args args)
{
INU_UpdExtProcComplete iNU_UpdExtProcComplete;
;
iNU_UpdExtProcComplete = INU_UpdExtProcComplete::construct();
if(iNU_UpdExtProcComplete.prompt())
iNU_UpdExtProcComplete.run();
}
--
static ClassDescription description()
{
return "@IST10759";
}
--
boolean validate()
{
boolean ret;
ret = super();
if(!winapi::fileExists(filenameOpen))
ret = checkFailed(strfmt("@SYS18678",filenameOpen));
return ret;
}
--
public boolean canGoBatch()
{
return true;
}
--
public boolean canGoBatchJournal()
{
return true;
}
2. implement the Run() in this method we can call our method which is created for logic(upload()).
3. Implement the pack and unpack methods
4. Implement the dialog() method
5. Construct() method
6. getFromDialog() method
7. Main method
8. Description method
9. Validate method
10.canGoBatch()
11.canGoBatchJournal
--
class INU_UpdExtProcComplete extends runbasebatch
{
DialogField dlgField;
FilenameOpen filenameOpen;
#define.CurrentVersion(1)
#define.Version(1)
#localmacro.CurrentList
filenameOpen
#endmacro
}
--
public void run()
{
if(filenameOpen)
{
if(WINAPI::fileExists(filenameOpen))
this.upload();
else throw error("@SYS26757");
}
super();
}
--
client static INU_UpdExtProcComplete construct()
{
return new INU_UpdExtProcComplete();
}
--
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
--
public boolean unpack(container packedClass)
{
Version version = Runbase::getVersion(packedClass);
switch(version)
{
case #CurrentVersion:
[version, #CurrentList] = packedClass;
break;
default:
return false;
}
return true;
}
--
public boolean getFromDialog()
{
boolean ret;
ret = super();
filenameOpen = dlgField.value();
return ret;
}
--
public Object dialog()
{
DialogRunbase dialog = super();
;
dlgField = dialog.addFieldValue(typeid(FilenameOpen),"","@IST10755","@IST10755");
return dialog;
}
--
void upload()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row;
FileName filename;
TINS_PurchTable tINS_PurchTable;
PurchId purchId;
str dataArea;
;
row++;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
filename = filenameOpen;
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("@SYS19358");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
purchId = cells.item(row, 1).value().bStr();
dataArea = cells.item(row, 2).value().bStr();
if(purchId)
{
ttsbegin;
select forupdate crosscompany purchTable
where purchTable.PurchId == purchId;
if(tINS_PurchTable.PurchId)
{
changecompany(dataArea)
{
purchTable.OneTimeVendor = Noyes::Yes;
purchTable.doupdate();
info("The purchase id %1 is updated successfully",purchTable.PurchId);
}
}
else
{
info(strfmt("@IST10757",purchId));
}
ttscommit;
}
else
{
throw error(strfmt("@IST10758"));
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
application.quit();
}
--
public static void main(Args args)
{
INU_UpdExtProcComplete iNU_UpdExtProcComplete;
;
iNU_UpdExtProcComplete = INU_UpdExtProcComplete::construct();
if(iNU_UpdExtProcComplete.prompt())
iNU_UpdExtProcComplete.run();
}
--
static ClassDescription description()
{
return "@IST10759";
}
--
boolean validate()
{
boolean ret;
ret = super();
if(!winapi::fileExists(filenameOpen))
ret = checkFailed(strfmt("@SYS18678",filenameOpen));
return ret;
}
--
public boolean canGoBatch()
{
return true;
}
--
public boolean canGoBatchJournal()
{
return true;
}
Subscribe to:
Posts (Atom)
Service class to get the selected record and deleted matching records and refresh the form data source in D365 F&O
[DataContractAttribute] class ABCUserProfilesBulkDeleteContract { UserId userId; [DataMemberAttribute('UserId')] pu...
-
Please click here to access Custom Workflow step by step process:
-
public InventQty onHandInventory(ItemId itemId, InventSiteId inventSiteId,InventLocationId inventLocation) { InventOnhand inventOnh...
-
1. In classDeclaration extend SrsReportDataProviderPreProcess instead of SrsReportDataProviderBase 2. Temp table properties should b...