Dynamics AX cross-company query with VendTrans and Global Address Book - view

I'm trying to create a simple cross-company query between VendTrans and VendTable. We have Global Address Book enabled so some entries are shared across companies. If I was writing SQL, it would look like:
select vtxn.Voucher, vtxn.TransDate, vt.AccountNum, vt.Name
from dbo.vendtrans vtxn
join dbo.vendtable vt on vtxn.accountnum = vt.accountnum
and vt.dataareaid in (vtxn.dataareaid, 'shr')
The problem I am encountering is that because of the global address book, I am getting no results from the query and view defined below. I would appreciate any help.
Thanks.
QUERY #spTestQuery
PROPERTIES
Name #spTestQuery
UserUpdate #No
Version #524
NextUniqueId #1008
AllowCrossCompany #Yes
ENDPROPERTIES
METHODS
Version: 3
SOURCE #classDeclaration
#public class QueryRun extends ObjectRun
#{
#}
ENDSOURCE
ENDMETHODS
BLOCKS
BLOCK #LedgerJournalTrans
PROPERTIES
Name #LedgerJournalTrans_1
Table #LedgerJournalTrans
UniqueId #1000
FirstFast #Yes
AllowAdd #No fields
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #BankChequeNum
FIELD #TransDate
ENDFIELDLIST
SORTING
ENDSORTING
LINES
LINE #BankChequeNum
PROPERTIES
Name #BankChequeNum
Table #LedgerJournalTrans
Field #BankChequeNum
Value #> 0
ENDPROPERTIES
ENDLINES
BLOCKS
BLOCK #VendTrans
PROPERTIES
Name #VendTrans_1
Table #VendTrans
UniqueId #1003
AllowAdd #No fields
FetchMode #1:1
Relations #Yes
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #AccountNum
FIELD #LastSettleVoucher
ENDFIELDLIST
SORTING
ENDSORTING
LINES
ENDLINES
BLOCKS
BLOCK #VendTable
PROPERTIES
Name #VendTable_1
Table #VendTable
UniqueId #1004
Relations #Yes
Enabled #No
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #Name
FIELD #AccountNum
ENDFIELDLIST
SORTING
ENDSORTING
LINES
ENDLINES
BLOCKS
ENDBLOCKS
ASSOCIATIONS
ASSOCIATION
MASTERFIELD #AccountNum
DETAILSFIELD #AccountNum
ENDASSOCIATIONS
ENDBLOCK
ENDBLOCKS
ASSOCIATIONS
ASSOCIATION
MASTERFIELD #AccountNum
DETAILSFIELD #AccountNum
ENDASSOCIATIONS
ENDBLOCK
BLOCK #LedgerTrans
PROPERTIES
Name #LedgerTrans_1
Table #LedgerTrans
UniqueId #1005
AllowAdd #No fields
FetchMode #1:1
Relations #Yes
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #AccountNum
FIELD #Voucher
FIELD #AmountMST
FIELD #TransDate
FIELD #Voucher
FIELD #Dimension
ENDFIELDLIST
SORTING
ENDSORTING
LINES
LINE #AccountNum
PROPERTIES
Name #AccountNum
Table #LedgerTrans
Field #AccountNum
Value #!211000
ENDPROPERTIES
ENDLINES
BLOCKS
BLOCK #LedgerTable
PROPERTIES
Name #LedgerTable_1
Table #LedgerTable
UniqueId #1006
AllowAdd #No fields
Relations #Yes
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #AccountName
FIELD #AccountNum
ENDFIELDLIST
SORTING
ENDSORTING
LINES
ENDLINES
BLOCKS
ENDBLOCKS
ASSOCIATIONS
ASSOCIATION
MASTERFIELD #AccountNum
DETAILSFIELD #AccountNum
ENDASSOCIATIONS
ENDBLOCK
BLOCK #Dimensions
PROPERTIES
Name #Dimensions_1
Table #Dimensions
UniqueId #1007
AllowAdd #No fields
ENDPROPERTIES
FIELDLIST
PROPERTIES
Dynamic #No
ENDPROPERTIES
FIELD #Description
FIELD #Num
FIELD #DimensionCode
ENDFIELDLIST
SORTING
ENDSORTING
LINES
LINE #DimensionCode
PROPERTIES
Name #DimensionCode
Table #Dimensions
Field #DimensionCode
Value #Purpose
ENDPROPERTIES
ENDLINES
BLOCKS
ENDBLOCKS
ASSOCIATIONS
ASSOCIATION
JOINDATASOURCE #LedgerTrans_1
MASTERFIELD #Dimension[3]
DETAILSFIELD #Num
ENDASSOCIATIONS
ENDBLOCK
ENDBLOCKS
ASSOCIATIONS
ASSOCIATION
MASTERFIELD #TransDate
DETAILSFIELD #TransDate
ASSOCIATION
MASTERFIELD #Voucher
DETAILSFIELD #Voucher
ENDASSOCIATIONS
ENDBLOCK
ENDBLOCKS
GROUPBY
ENDGROUPBY
ORDERBY
ENDORDERBY
ENDBLOCK
ENDBLOCKS
DEPENDENTS
DEPENDENT
PROPERTIES
Name #spTestView
DependentType #View
ENDPROPERTIES
Id 50005
ENDDEPENDENTS
COMPOSITEQUERIES
ENDCOMPOSITEQUERIES
ENDQUERY
VIEW #spVendTestView
Id 50008
PROPERTIES
Name #spVendTestView
SaveDataPerCompany #Yes
Query #spvendtest
ENDPROPERTIES
QUERY #Metadata
PROPERTIES
Name #Metadata
AllowCrossCompany #Yes
ENDPROPERTIES
BLOCKS
ENDBLOCKS
QUERY #spVendTest
ENDQUERY
ENDQUERY
FIELDS
VIEWFIELD #Voucher
Id 50001
PROPERTIES
Name #Voucher
Table #spVendTestView
ExtendedDataType #Voucher
StringSize #25
DataSource #VendTrans_1
DataField #Voucher
ENDPROPERTIES
ENDVIEWFIELD
VIEWFIELD #TransDate
Id 50003
PROPERTIES
Type #Date
Name #TransDate
Table #spVendTestView
ExtendedDataType #TransDate
StringSize #(Memo)
DataSource #VendTrans_1
DataField #TransDate
ENDPROPERTIES
ENDVIEWFIELD
VIEWFIELD #AccountNum
Id 50004
PROPERTIES
Name #AccountNum
Table #spVendTestView
ExtendedDataType #VendAccount
StringSize #20
DataSource #VendTable_1
DataField #AccountNum
ENDPROPERTIES
ENDVIEWFIELD
VIEWFIELD #Name
Id 50002
PROPERTIES
Name #Name
Table #spVendTestView
ExtendedDataType #VendName
StringSize #120
DataSource #VendTable_1
DataField #Name
ENDPROPERTIES
ENDVIEWFIELD
ENDFIELDS
GROUPS
ENDGROUPS
ENDVIEW

I can see you define a query with crosscompany then define a view based on the query.
However the crosscompany on the query does not imply that the view is crosscompanyalso.
Have a look on Cross-Company Queries for Views.
Excerpt:
In the Application Object Tree (AOT), you can build a view by dragging
a query node onto the Data Sources node of your view. The query could
have the AllowCrossCompany property set to Yes. However, this will not
return cross-company results from the view.
To return cross-company results from a view, you need to use the
crossCompany keyword on the select statement that reads from the view.
The AllowCrossCompany setting on the view's data source query is
ignored in X++ select statements that read from a view.

Related

Set interactive grid value based on dropdown select list

I am trying to make a cost value populate in an interactive grid column based on the value selected in an Item column.
My setup is:
An "Item" table which contains a list of Items, and the "Cost" assigned to the item.
A "Quote" table which contains general info about the quote, i.e. company name, date created, signed, signed date etc.
A "Quote_Items" table which assigns an Item to a quote by Quote_ID, and Item_ID. I added a Cost column to the Quote Items table to be able to see it in the interactive grid, and update it.
For the Quote Items I created an Interactive grid to add Items to the quote.
I set the Item_ID column in my interactive grid to a popup LOV which populates the Item_ID based on the selected item.
To populate the "Quote_Item.Cost" I added a dynamic action to the Item_ID column to:
Event:Change
selection Type: Column(s)
Region: ..Item List
Column(s): Item_ID
Action: Set Value
Set Type: SQL Statement
SQL Statement: SELECT I.COST
FROM WIP_ITEMS I
WHERE I.ITEM_ID = ITEM_ID
Items to Submit: COST
The result is, when I select an Item from the dropdown, all values in the "Items.Cost" table are displayed in comma separated values in the field:
Quote Item populating all item costs in one field
It seems like the "WHERE I.ITEM_ID = ITEM_ID" part of the SQL query is not working correctly? How can I get it to show only the Value associated with the Item_ID?
Syntax to reference a column in the SQL query > :COLUMN_NAME
So your SQL query should looks like this:
SELECT i.cost
FROM wip_items i
WHERE i.item_id = :ITEM_ID
And you need to modify the "Items to Submit" parameter too, because it must always be the value which your reference in the where condition, so in your case it should be:
Items to Submit: ITEM_ID

where are category NAMES stored in magento?

Seems like this should be a findable question but I could not locate it.
Where is the category NAME stored in the magento database? I can see catalog_category_entity has the key ID, and then there are the other EAV tables. But I cannot find the actual name of the category stored in any table prefixed by catalog_category.
At least with products the catalog_products_entity table has the SKU (some human-readable value) in it.
The categories names are in the table catalog_category_entity_varchar
The request you are looking for :
select cat.*, cv.value as `category_name` from `catalog_category_entity` as cat
join `catalog_category_entity_varchar` as cv on cat.entity_id = cv.`entity_id`
join `eav_attribute` as att on att.`attribute_id` = cv.`attribute_id`
join `eav_entity_type` as aty on att.`entity_type_id` = aty.`entity_type_id`
where aty.`entity_model` = 'catalog/category' and att.`attribute_code` = 'name' and cv.`store_id` = 0
Please note that this is the name of your categories for your default store view.
If you do have multiple store or store view in your magento you just have to adapt the condition cv.`store_id` = 0.
The list of your stores can be found in the table core_store
'name' is an EAV attribute of type VARCHAR so you can find the values for that attribute on the catalog_category_entity_varchar table, but it contains all values for attributes that are type VARCHAR, so to query for only the values for the name attribute you have to find what the attribute id is, which you can find in that eav_attributes table using something like:
SELECT * FROM `eav_attribute` WHERE `entity_type_id` = ##CATEGORY ENTITY TYPE ID## AND `attribute_code` = 'name'
If you have ID's with you then this works:
SELECT DISTINCT value, entity_id FROM catalog_category_entity_varchar WHERE entity_id IN (ID's of the category) AND attribute_id = 111 AND STORE = 0
Make sure to replace "ID's of the category" with ID's seperated by commmas and Store ID too. ) is default Store ID.

Rename custom attribute from sales/quote in Magento

I am trying to rename a custom attribute in Magento, the following code adds the attribute I just need the equivalent to remove using the Magento installer scripts:
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "is_school", array(
"type" => "int",
"backend" => "",
"label" => "Organisation Type?",
"input" => "int",
"source" => "",
"visible" => false,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
"note" => ""
));
$installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'is_school', 'int(11)');
$installer->getConnection()->addColumn($installer->getTable('sales/order'), 'is_school', 'int(11)');
// need code to rename these two column above from is_school to 'org_type'
$installer->endSetup();
$installer->getConnection()
->changeColumn($tableName, $oldColumnName, $newColumnName,$definition);
Where
`changeColumn` method is used to modify and rename existing column in the table. It has such parameters:
$tableName - the table name that should be modified
$oldColumnName- the old name of the column, that should be renamed and modified
$newColumnName- a new name of the column
$definition - a new definition of the column (INT(10), DECIMAL(12,4), etc)
For more information
addColumn() method adds new column to exiting table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should be added
$definition - definition of the column (INT(10), DECIMAL(12,4), etc)
addConstraint() method creates a new constraint foreign key. It has such parameters
$fkName - the foreing key name, should be unique per database, if you don't specify FK_ prefix, it will be added automaticaly
$tableName - the table name for adding a foreign key
$columnName - the column name that should be refered to another table, if you have complex foreign key, use comma to specify more than one column
$refTableName - the foreign table name, wich will be handled
$refColumnName - the column name(s) in the foreign table
$onDelete - action on row removing in the foreign table. Can be empty string (do nothing), cascade, set null. This field is optional, and if it is not specified, cascade value will be used.
$onUpdate action on row key updating in the foreign table. Can be empty string (do nothing), cascade, set null. This field is optional, and if it is not specified, cascade value will be used.
$purge - a flag for enabling cleaning of the rows after foreign key adding (e.g. remove the recodrs that are not referenced)
addKey() method is used for adding of indexes to a table. It has such parameters:
$tableName - the table name where the index should be added
$indexName - the index name
$fields - column name(s) used in the index
$indexType - type of the index. Possible values are: index, unique, primary, fulltext. This parameter is optional, so the default value is index
dropColumn() method is used for removing of columns from the existing table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should removed
dropForeignKey() method is used for removing of foreing keys. It has such parameters:
$tableName - the table name for removing a foreign key
$fkName - the foreing key name
dropKey() method is used for removing of the table indexes. It has such parameters:
$tableName - the table name where the index should be removed
$keyName - the index name
modifyColumn method is used to modify existing column in the table. It has such parameters:
$tableName - the table name that should be modified
$columnName- the name of the column, that should be renamed
$definition - a new definition of the column (INT(10), DECIMAL(12,4), etc)
changeColumn method is used to modify and rename existing column in the table. It has such parameters:
$tableName - the table name that should be modified
$oldColumnName- the old name of the column, that should be renamed and modified
$newColumnName- a new name of the column
$definition - a new definition of the column (INT(10), DECIMAL(12,4), etc)
changeTableEngine method is used to change table engine, from MyISAM to InnoDB for instance. It has such parameters:
$tableName - the table name
$engine - new engine name (MEMORY, MyISAM, InnoDB, etc)
Let me know if you have any query

Fetch value from database table where one column of table(foreign key) is equal to input value

I am using linq to fetch value from database table where one column of table (foreign key) is equal to input value but I am not getting that property when writing linq.
var country =
from x in db.Viewerships
where x.AssetId == model.ID
select x.CountryName;
In above code x.AssetId is not found because AssetId is used as foreign key in the table.
When you add the tables in your model, there is checkbox which says "Include foreign key columns in the model", if you didn't tick this option, it will NOT include the Foreign Key Columns in your entity. However it will by default create the navigational property for the other entity, so you have 2 options
Either re-add the table with said option ticked
Use the navigational property like this
Code:
var country =
from x in db.Viewerships
where x.Asset.ID == model.ID
select x.CountryName;
Assuming your Asset is the navigational property and Asset table's Primary key column is ID

Creating multi-column constraints depending on column value

I'm trying to create a constraint on an oracle database that says the following:
If column1 == someValue then the combination of column2 and column3 has to be unique for all entries with column1 == someValue
I'm familiar with the concepts of unique and check constraints, and I've tried expressing the constraint with those constructs. However, I can't seem to find a way to include the condition. Which is why I'm wondering if it is even possible.
The table I want to create constraint for is created by Hibernate mapping the following class hierarchy (most of the attributes ommited for brevity):
class MyClass {
String name;
MyClass parent;
}
class MySubClass extends MyClass {
String businessValue;
}
The classes are mapped using a single table strategy and using different discriminator values for each type. It's a customer requirement that for all instances of MySubClass the combination of name and parent has to be unique (column1 would be the discriminator value). It would be easy to enforce such a constraint on the parent class through a table constraint. However, that constraint must only apply to MySubClass.
There is the possibility of validating the data before entering it into the the database with frameworks such as Hibernate Validator. But since the validation would need database access anyway, a database constraint seems the more performance saving way to do it.
You can't do this with a constraint, but you can do it using a "function-based index" (FBI) like this:
create unique index mytable_idx on mytable
( case when column1 = 'somevalue' then column2 end
, case when column1 = 'somevalue' then column3 end
);
This only creates unique index entries for rows with column1 = 'somevalue', so other rows can contain duplicates but these cannot.

Resources