This post is machine-translated. The original post in german language can be found here.
These post applies to following version:
Dynamics AX 2012
Dynamics AX 2012
|
|
|
Thank you very much for this code! Upon implementation however I noticed it wasn't complete. InventTable.productname() at one point calls EcoResProductTranslation::findByProductOrSystemLanguage(). That method searches for a translation in the companyInfo language, but when that translation isn't found it also searches for a translation in the system language. That last piece was missing from the snippt. i added it and the method now looks like this: private static server str compColItemName() { #define.ViewName("AXTdps_ProdRouteDimReqTransView") #define.DataSourceName("InventTable") #define.FieldItemId("ItemId") #define.FieldProduct("Product") str sProduct; DictView dictView; str ret; str translationSQLStrCompLang, translationSQLStrSysLang; str productSQLStr; dictView = new DictView(tableNum(#ViewName)); sProduct = dictView.computedColumnString (#DataSourceName, #FieldProduct, FieldNameGenerationMode::FieldList, true); translationSQLStrCompLang = strFmt("SELECT Name FROM EcoResProductTranslation WHERE EcoResProductTranslation.Product = %1 AND LanguageId = '%2'", sProduct, CompanyInfo::find().LanguageId); translationSQLStrSysLang = strFmt("SELECT Name FROM EcoResProductTranslation WHERE EcoResProductTranslation.Product = %1 AND LanguageId = '%2'", sProduct, SystemParameters::getSystemLanguageId()); productSQLStr = strFmt("SELECT DisplayProductNumber FROM EcoResProduct WHERE EcoResProduct.RecId = %1", sProduct); ret = strFmt("isNUll((%1), (%2))", translationSQLStrCompLang, translationSQLStrSysLang); ret = strFmt("isNUll((%1), (%2))", ret, productSQLStr); return ret; } |
Thank you very much for your extension. So everybody, who is looking for a replacement for the itemName()-method, should use the code of Jos. |
Can this be added to PurchLineOpenOrder form? How would you set up the joinsource on the view once added to the above form? |
Yes, you can use the abobe view in form PurchLineOpenOrder. You have to do the following steps: 1) Add view as new dataSource to form 2) Set properties of this new datasource: JoinSource: PurchLine LinkType: InnerJoin 3) Overwrite the init()-Method of the new datasource like the following public void init() { super(); this.query().dataSourceName(this.name()).clearLinks(); this.query().dataSourceName(this.name()).clearDynalinks(); this.query().dataSourceName(this.name()).addlink(fieldNum(PurchLine, ItemId), fieldnum(ItemNameView, ItemId)); } Please note, that there are additional steps needed, depending on your form. Especially if your form is not a "read-only" form like PurchLineOpenOrder is. |
|
|
I think the computed column gets only executed once (during synchronization) - just check the generated view direct in SQL. In this case the language info from SystemParameters should only work if you have just one single partition and language from CompanyInfo will not work (i assume it uses the company settings from dat or to be more precise, the company it's in during synchronization) :-/ |
|
|
|
|
|
|
Using computed columns of view creates you the ability, to write subselects/subqueries.
Find below a method, which is inspired by inventTable.productName() and can be used to display the name of an item.
A view cotaining the above method could look like in the screenshot shown.
Such a view could be, for example, a replacement for display methods in forms. This would have the advantage that you could sort or filter by the item name.
However, such use may also have disadvantages, such as the contents of a computed column is not updated immediately after entering the item number (like a display method do).