Basic structure of Batch Job in AX 2012 using X++
class BEProjectEmailAutomationBatch extends RunBaseBatch
{
}
public void run()
{
//write login in this method
}
public container pack()
{
return conNull();
}
public boolean unpack(container packedclass)
{
return true;
}
public static ClassDescription description()
{
return "Project Report Email Automation";
}
public static void main(Args _args)
{
BEProjectEmailAutomationBatch EmailAutomation = new BEProjectEmailAutomationBatch();
if (EmailAutomation.prompt())
{
EmailAutomation.run();
}
}
Tuesday, April 7, 2020
Monday, April 6, 2020
Export template in AX 2012 X++
today we will see how to export template like if you have written any uploaded but after some time you don't remember which value will come first or you forget the sequence.
// FileName fileName = @'C:\\Desktop\\Mounting\\Mounting Journal.xlsx';
For this situation we will make the template you just need to fill the template and then import the data in ax 2012.
class BEUploadTickets extends RunBaseBatch
{
DialogRunbase dialog;
DialogField fileNameField;
FilenameOpen csvFileName;
}
protected Object dialog()
{
container conFilter;
DialogText dlgText;
DialogGroup exportGroup, importGroup;
FormBuildControl dialogGroupControlExp, dialogGroupControlImp;
FormBuildButtonControl exportTemplateButton;
;
#File
dialog = super();
conFilter = ['Excel File","*.xlsx'];
importGroup = dialog.addGroup('Import');
dialogGroupControlImp = dialog.formBuildDesign().control(importGroup.formBuildGroup().id());
fileNameField = dialog.addField(extendedTypeStr('FilenameOpen'));
dialog.filenameLookupFilter(conFilter);
dlgText = dialog.addText('\nPlease Select a EXCEL file to upload Ticket info data.');
dlgText.displayHeight(3);
exportGroup = dialog.addGroup('Export');
dialogGroupControlExp = dialog.formBuildDesign().control(exportGroup.formBuildGroup().id());
exportTemplateButton = dialogGroupControlExp.addControl(FormControlType::Button,'exportTemplateButton');
exportTemplateButton.text("@SYS91539");
exportTemplateButton.backgroundColor(10);
exportTemplateButton.backStyle(5);
exportTemplateButton.bold(15);
exportTemplateButton.foregroundColor(7);
return dialog;
}
public void dialogPostRun(DialogRunbase _dialog)
{
super(dialog);
_dialog.formRun().controlMethodOverload(true);
_dialog.formRun().controlMethodOverloadObject(this);
}
protected void exportTemplate()
{
#AviFiles
SysOperationProgress progress1 = new SysOperationProgress();
SysExcelApplication sysExcelApplication;
SysExcelWorkbooks sysExcelWorkBooks;
SysExcelWorkbook sysExcelWorkBook;
SysExcelWorkSheets sysExcelWorkSheets;
SysExcelWorkSheet sysExcelWorkSheet;
SysExcelWorksheet sysExcelWorkSheetToBeDeleted;
SysExcelStyles styles;
SysExcelStyle style;
SysExcelFont font;
SysExcelCells cells;
int row = 1;
boolean workSheetAdded = false;
;
progress1.setCaption('Export To Excel in progress...');
progress1.setAnimation(#AviTransfer);
sysExcelApplication = SysExcelApplication::construct();
sysExcelWorkBooks = sysExcelApplication.workbooks();
sysExcelWorkBook = sysExcelWorkBooks.add();
styles = sysExcelWorkBook.styles();
style = styles.add('Header');
font = style.font();
font.bold(true);
font.color(255);
sysExcelWorkSheets = sysExcelWorkbook.worksheets();
sysExcelApplication.visible(true);
while(sysExcelWorkSheets.count() > 1)
{
sysExcelWorkSheetToBeDeleted = sysExcelWorkSheets.itemFromNum(2);
sysExcelWorkSheetToBeDeleted.delete();
}
sysExcelWorkSheet = sysExcelWorkSheets.add(null,null,1);
sysExcelWorkSheet.name('Ticket Uploader Template');
sysExcelWorkSheet.cells().item(1,1).value('Ticket Type');
sysExcelWorksheet.cells().item(1,2).value('Ticket sub type ID');
//sysExcelWorksheet.cells().item(1,3).value('');
sysExcelWorksheet.cells().item(1,4).value('Contract Id');
sysExcelWorksheet.cells().item(1,5).value('Property Id');
sysExcelWorksheet.cells().item(1,6).value('Move In Customer');
sysExcelWorksheet.cells().item(1,7).value('Disconnection Date');
sysExcelWorksheet.cells().item(1,8).value('DL Charge Date');
sysExcelWorksheet.cells().item(1,9).value('Settlement Date');
sysExcelWorksheet.rows().item(1).style('Header');
{
progress1.setText(strfmt("@BEL958"));
sysExcelWorksheet.columns().autoFit();
cells = sysExcelWorksheet.cells();
cells.range('D2:D99').numberFormat('0,00');
workSheetAdded = false;
}
sysExcelWorksheet.columns().autoFit();
sysExcelApplication.displayAlerts(false);
}
public void exportTemplateButton_clicked()
{
this.exportTemplate();
}
public static void main(Args _args)
{
BEUploadTickets uploadsTicket = new BEUploadTickets();
if(uploadsTicket.prompt())
{
BEUploadTickets::uploadandValidateData();
}
}
private static void uploadandValidateData()
{
For this please check the link how to import data from excel.
https://dynamicszerotohero.blogspot.com/2020/04/x-import-data-from-excel-ax-2012.html
https://dynamicszerotohero.blogspot.com/2020/04/x-import-data-from-excel-ax-2012.html
}
see the below image when you click on the Create Template button
Fill all the values in it and import the file.
Left Right String padding in X++
We will see how to add the character on the left side or the right side of string.
it is very simple for this we will use two functions.
For right side padding we use strLfix(str _str, int _lenght [, char _char])
For Left side padding we use strRfix(str _str, int _lenght [, char _char])
str text = "Score";
str leftPadding,rightpadding;
// for right side padding we use strLFix function
leftPadding = strLFix(text,strLen(text)+1,'s');
info(strFmt("Right side padding result - %1",leftPadding));
// for left side padding we use strRFix function
rightpadding = strRFix(text,strLen(text)+1,'s');
info(strFmt("Left side padding result- %1",rightpadding));
it is very simple for this we will use two functions.
For right side padding we use strLfix(str _str, int _lenght [, char _char])
For Left side padding we use strRfix(str _str, int _lenght [, char _char])
str text = "Score";
str leftPadding,rightpadding;
// for right side padding we use strLFix function
leftPadding = strLFix(text,strLen(text)+1,'s');
info(strFmt("Right side padding result - %1",leftPadding));
// for left side padding we use strRFix function
rightpadding = strRFix(text,strLen(text)+1,'s');
info(strFmt("Left side padding result- %1",rightpadding));
Wednesday, April 1, 2020
x++ Import data from excel ax 2012
In this post we check how to import data from excel in AX 2012 using X++.
we Import data from excel and check if the record exist in table then update the field otherwise print the excel row number which has failed.
static void UpdateOldProperty(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
FileName filename;
int row =1; //ignore header row
int i=0,failed=0;
Dialog dialog;
DialogField dialogField;
BEProperties properties,properties1;
BEPropertyID propertyID;
BEOldPropertyID OldPropertyID;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
filename = (dialogfield.value());
}
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
startLengthyOperation();
do
{
row++;
OldPropertyID = COMVariant2Str(cells.item(row,1).value());
propertyID = BEProperties::find(COMVariant2Str(cells.item(row,2).value())).PropertyID;
if(!propertyID)
{
info(strFmt("RowNo. %1, PropertyID %2, OldPropertyID %3",row,propertyID,OldPropertyID));
failed++;
}
else
{
ttsBegin;
select forUpdate properties1 where properties1.PropertyID == propertyID;
properties1.OldPropertyID = OldPropertyID;
properties1.update();
ttsCommit;
i++;
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
workbook.close();
application.quit();
endLengthyOperation();
info(strFmt("%1 Records Updated and %2 records failed",i,failed));
}
we Import data from excel and check if the record exist in table then update the field otherwise print the excel row number which has failed.
static void UpdateOldProperty(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
FileName filename;
int row =1; //ignore header row
int i=0,failed=0;
Dialog dialog;
DialogField dialogField;
BEProperties properties,properties1;
BEPropertyID propertyID;
BEOldPropertyID OldPropertyID;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
filename = (dialogfield.value());
}
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
startLengthyOperation();
do
{
row++;
OldPropertyID = COMVariant2Str(cells.item(row,1).value());
propertyID = BEProperties::find(COMVariant2Str(cells.item(row,2).value())).PropertyID;
if(!propertyID)
{
info(strFmt("RowNo. %1, PropertyID %2, OldPropertyID %3",row,propertyID,OldPropertyID));
failed++;
}
else
{
ttsBegin;
select forUpdate properties1 where properties1.PropertyID == propertyID;
properties1.OldPropertyID = OldPropertyID;
properties1.update();
ttsCommit;
i++;
}
type = cells.item(row+1, 1).value().variantType();
}
while (type != COMVariantType::VT_EMPTY);
workbook.close();
application.quit();
endLengthyOperation();
info(strFmt("%1 Records Updated and %2 records failed",i,failed));
}
Monday, March 30, 2020
Hide Query Select button in ax 2012
In this blog post we will see how to Disable or Hide the query select button using controller class.
override the showQuerySelectButton method in controller class and just add ret = false;
public boolean showQuerySelectButton(str parameterName)
{
boolean ret;
ret = super(parameterName);
ret = false;
return ret;
}
override the showQuerySelectButton method in controller class and just add ret = false;
public boolean showQuerySelectButton(str parameterName)
{
boolean ret;
ret = super(parameterName);
ret = false;
return ret;
}
AX 2012 Roles Associated with current user Using X++
In this blog post we will will find the Security Role assigning to the particular user using X++ in AX 2012.
SecurityRole role;
SecurityUserRole userRole;
UserInfo userinfo;
While select role
exists join userRole
where role.RecId == userRole.SecurityRole
&& userRole.User == curUserId()
{
info(role.Name );
}
SecurityRole role;
SecurityUserRole userRole;
UserInfo userinfo;
While select role
exists join userRole
where role.RecId == userRole.SecurityRole
&& userRole.User == curUserId()
{
info(role.Name );
}
Wednesday, March 18, 2020
add address tab on custom form D365FO
In this post we see how to add address tab on custom form dynamics 365 finance and operation. The scenario was to add the tab on custom form same like as on customer or vendor form.
For this scenario we will look how to add the address tab.
Step 1: Create new table or add the DirPartyRecid on your table and make the relationship with DirPartyTable
Step 2: Create new form or add MainTable and DirPartTable in form datasource
Step 3: Set the properties on DirPartyTable datasource
Step 4: Add tab page on form and add form part control in it
Step 5: Set the properties on the form part control in the Menu Item Name set (LogisticsPostalAddressGridFormPart)
Step 6: Add link and set the properties on it.
Step 7: See the results as shown below
For this scenario we will look how to add the address tab.
Step 1: Create new table or add the DirPartyRecid on your table and make the relationship with DirPartyTable
Step 2: Create new form or add MainTable and DirPartTable in form datasource
Step 3: Set the properties on DirPartyTable datasource
Step 4: Add tab page on form and add form part control in it
Step 5: Set the properties on the form part control in the Menu Item Name set (LogisticsPostalAddressGridFormPart)
Step 6: Add link and set the properties on it.
Step 7: See the results as shown below
Subscribe to:
Posts (Atom)