Dynamics AX Blog - Dynamics AX 4.0 - Page 2

RSS-Feed of this version
Print text-document using X++Below you'll find a example, how to print a Text-document using X++. static void printTextFileFromAX(Args _args) { WinAPI::shellExecute("c:\windows\system32\NOTEPAD.EXE", @'/pt "c: emp est.txt" "An OneNote 2010 senden"'); } Note: "An OneNote 2010 senden" is the name of the printer. |
Move pallet using X++Using the following code, you will be able to move a pallet per code. WMSPalletMove wmsPalletMove = new wmsPalletMove();
wmsPalletMove.parmWMSPalletId('00000022_117'); wmsPalletMove.parmToInventLocationId('300'); wmsPalletMove.parmToLocationId('01'); if(wmsPalletMove.validate()) { wmsPalletMove.run(); }
|
What is the difference between update and doUpdate?What is the difference between update() and doUpdate()? You canfind the answer on MSDN or you take a look at the following table.
| ||||||||
Working with the calling object of a form (Caller)The following method contains some snippets that can be used to call various functions/methods of the calling object (form). If you change element.args() to e.g. _args and pass the arguments to the method, you can use the code within a class as well. void workWithCallingRecord() { common common; object object; formDataSource formDataSource; formRun formRun; inventDim inventDim; salesTable salesTable; int i; ; // Call method from calling record if( element.args() && element.args().record() ) { common = element.args().record(); if(common.isFormDataSource()) { info(tableId2Name(common.TableId)); if(formDataSourceHasMethod(common.dataSource(), identifierStr("someMethod"))) { object = common.dataSource(); object.someMethod(); } } } // Call method from calling form if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); if(sysFormRun::hasMethod(formRun, identifierStr("someFormMethod"))) { object = formRun; object.someFormMethod(); } } // Get value from calling record if( element.args() && element.args().record() ) { common = element.args().record(); if(common.TableId == tableNum(salesTable)) { info(common.(fieldNum(salesTable, salesId))); } } // Get value from calling datasource (form with multiple datasources) if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); for (i = 0; i <= formRun.dataSourceCount(); i++) { formDataSource = formRun.datasource(i); if (formDataSource && formDataSource.table() == tablenum(inventDim)) // Search for specific table { inventDim = formDataSource.cursor(); break; } } if(inventDim) { info(inventDim.InventLocationId); } } // Change data in calling datasource if(element.args() && element.args().caller() && element.args().caller().handle() == className2Id('formRun')) { formRun = element.args().caller(); for (i = 0; i <= formRun.dataSourceCount(); i++) { formDataSource = formRun.datasource(i); if (formDataSource && formDataSource.table() == tablenum(salesTable)) // Search for specific table { salesTable = formDataSource.cursor(); break; } } if(salesTable) { // Update data salesTable.PurchOrderFormNum = "Some value"; salesTable.update(); } } // Refresh calling datasource if( element.args() && element.args().record() ) { common = element.args().record(); if(common.isFormDataSource()) { formDataSource = common.dataSource(); formDataSource.research(true); } } } |
Dynamics AX: Illegal property valueIf you try to change the AllowDuplicates-Property of a table index from No to Yes, the following error message may occur: Illegal property value In this case, presumably, the affected index is registered as PrimaryIndex or ClusteredIndex of the table. |
Dynamics AX: Print SalesInvoice through codeUsing the following code you can easily print sales invoice through code. With slight modifications to the code, this is also true for all other sales- and purchase-sided documents. Short example in AX 2009 static void PrintSalesInvoice(Args _args) { custInvoiceJour custInvoiceJour; SalesFormLetter salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice, false); PrintJobSettings printJobSettings = new PrintJobSettings(); Args args = new Args(); boolean prompt = true; boolean printIt = true; ; if (prompt) { // Dialog printIt = printJobSettings.printerSettings('SysPrintForm'); } else { // Printjobsettings printJobSettings.setTarget(PrintMedium::File); printJobSettings.format(PrintFormat::PDF); printJobSettings.fileName(@'c: empmyfile.pdf'); } if (!printIt) { return; } salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings()); select firstOnly custInvoiceJour where custInvoiceJour.salesid == '100001'; args.record(custInvoiceJour); args.caller(salesFormLetter); new MenuFunction(menuitemoutputstr(SalesInvoice), MenuItemType::Output).run(args); } Short example in AX 4.0 static void PrintSalesInvoice(Args _args) { custInvoiceJour custInvoiceJour; SalesFormLetter salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice, false); PrintJobSettings printJobSettings = new PrintJobSettings(); Args args = new Args(); boolean prompt = true; boolean printIt = true; salesPrintSetup salesPrintSetup; ; if (prompt) { // Dialog printJobSettings = new PrintJobSettings(salesPrintSetup.PrintJobSettings); printIt = printJobSettings.printerSettings('SysPrintForm'); salesPrintSetup.PrintJobSettings = printJobSettings.packPrintJobSettings(); } else { // Printjobsettings printJobSettings.setTarget(PrintMedium::File); printJobSettings.format(PrintFormat::PDF); printJobSettings.fileName(@'c: empmyfile.pdf'); } if (!printIt) { return; } salesFormLetter.updatePrinterSettingsFormLetter(printJobSettings.packPrintJobSettings()); select firstOnly custInvoiceJour where custInvoiceJour.salesid == '100001'; args.record(custInvoiceJour); args.caller(salesFormLetter); new MenuFunction(menuitemoutputstr(SalesInvoice), MenuItemType::Output).run(args); } |
|
|
|
|
|
|
The following code is an example of how to build a query range based on a Form Data Source, which displays only "daily" records.
In the example the form-dataSource is named DataSourceName and it contains two date fields called FromDate and ToDate. Depending on a check box only records should be displayed, which that are valid for todays date.
{
queryBuildRange qbr;
qbr = sysQuery::findOrCreateRange(DataSourceName_ds.queryBuildDataSource(), fieldNum(DataSourceName, recId));
if( !ShowExpiredCheckBox.checked())
{
qbr.value(strfmt('('+
'((%5.%2 <= %1) && (%5.%3 >= %1)) || ' +
'((%5.%2 == %4) && (%5.%3 == %4)) || ' +
'((%5.%2 <= %1) && (%5.%3 == %4)) || ' +
'((%5.%3 >= %1) && (%5.%2 == %4)) ' +
')',
Date2StrXpp(systemDateGet()),
fieldstr(DataSourceName, FromDate),
fieldstr(DataSourceName, ToDate),
Date2StrXpp(dateNull()),
tableId2name(tableNum(DataSourceName))));
}
else
{
qbr.value(SysQuery::valueUnlimited());
}
}
The above method can be called for example in the executeQuery() of the DataSource.