How to show selected items of certain table on the different table in Dynamics AX 2012? - x++

So, I have two tables InventTable (for inverntory) and MyCartTable. I want to connect this tables so when I chose some item or items in InventTable to show in MyCartTable's grid. MyCartTable fields are ItemNumber, ProductName, PartyID;

Assuming you are working with AX 2012:
On your MyCartTable, remove the itemNumber field.
Open an other AOT windows go to Data Dictionary - Extended Data Types and locate the itemId data type. Drag and drop this data type on your table. AX will ask if you want to add a foreign key relation. Click yes, this will add a relation to the InventTable to the relations node of your table.
Now on your form, set the JoinSource property of your MyCartTable to you inventTable data source.
If you are having trouble making this work, create a new form with only those two datasources and a minimum amount of controls (like just 2 grids), this allows you to test this more easily.

Related

Create DBGrid columns at runtime with diffrent dataset (Table)

I want to create only certain columns on my "dbgrid" at run-time, and set them to
other table field(s) or same field . How do you do that :
illustration:
I have 3 Tables :
Student(IdStudent, NameStudent ...) ,
Module(idModul,NameModule...),
Notes(idNote,idStudent,idModul,Note).
I Want to insert All Notes in one Dbgrid and names of columns of DBgrid are names of Module Table. I have No idea?
Thanks.
You cannot do this with a dbgrid; dbgrids have only one datasource and a datasource has only one dataset. If you are using an SQL compliant database you should look into a join and/or crosstab to return a single dataset. (I think this is what MartynA is talking about) Or create a clientdataset at run-time and build it with the columns/data you want if you want data-aware. I would look into using a stringgrid, listview or treeview and build the whole thing by hand.

Master/Child with alternative linking fields in the child table

There is probably a simple solution to this but I'm stumped.
I have a master table with one ID field. There is a child table with that ID in two possible fields. Think of a doubles team with Player A and Player B. The Master table will have two records, one for each player. The Child will have one record with the Player A ID in one field and the Player B ID in a second field.
When I use the Master/Child and I'm sitting on Player A I will only see the child records if Player A is in the first ID field. If I move to Player B then I see nothing in the child table if Player B ID is in the second field.
Any help?
Thanks,
Don
Gday,
If I read you aright, you want to return each child row that has the parent ID in either A or B.
To do this in a query, you could write:
select A, field1, field2...
from
childtable
where
A = :keyvalue
union all
select B, field1, field2...
from
childtable
where
B = :keyvalue
Hope it helps!
The Child will have one record with the Player A ID in one field and the Player B ID in a second field.
In that case, you should consider using an fkInternalCalc field on the Detail table (if your TDataSet type supports fkInternalCalc fields, and deriving its value in the Detail's OnCalcFields event however suits your data model) and use that as the Detail field in an Index on the Detail table for selecting records which match the master. But generally speaking, needing to do that (i.e, link the Detail records on values from different fields) is a sign of imperfect data-modelling** - you might do better to have an intermediate "linking" table between the two tables you currently have,e.g. linking the Detail records to the Master on the basis of PlayerID, regardless of whether the player is "PlayerA" or "PlayerB".
** - the reason being that, as you have obviously gathered, the Master could be linked to the Detail on the basis of two different fields in the Detail table, and that does not fit with how M-D relationships traditionally work in Delphi (i.e. a single field or combination of fields with no alternatives) and in fact an extra, "linking" table is the better way to model the situation where the link needs to be defined on the basis of the values in Detail fields IDFieldA and IDFieldB.
Btw, what TDataSet descendant types are you using?
The simpler and much faster running answer to the UNION ALL join is
SELECT Mast.* ,DetA.* ,DetB.* FROM
MAST
JOIN Det AS DetA ON Mast.AID=DetA.Det_ID
JOIN Det AS DetB ON Mast.BID=DetB.Det_ID
If you want to be able to have any number of players in the game, then each Det record (player) needs to point to the master using the Mast_ID. You can do a similar join that way, but you will get one record per player if you do. The way I did it above gives you one record for each master/detail A/Detail B combination.

Backendless iOS: intermediate table between two tables

I am new in Backendless and I have read all the manuals about relations, but still not sure how to create san intermediate table between two tables.
For instance, I have table called users and tables called Events. A user can subscribe to events. So I want new table UserEvents, which has user_id and event_id. Also, how would I retrieve all events added by user? In other words, how to do joins in Backendless?(I suppose there is no joins and everything much simpler though).
Thank you very much!
There are two separate questions at hand here:
How to create relationships between objects?
How to load objects created by a user?
Let's start with the first one:
How to create relationships between objects?
When you work with Backendless it is important to think in terms of objects and not tables. For example if there is an entity called Order and it contains a collection of OrderItem objects, then THAT is your data structure. You do not need to pre-create tables in console – Backendless will do it for you the very first time you save an Order object which has a collection of OrderItems. However, if you would like to do it by hand in our Console, here are the steps:
Login to console, select an app, click on Data
Create table Order (it is better to name tables in the singular form - so Order, not Orders).
When you create a new table (click the "+" button in the lower-left corner), console will prompt you to switch to Schema Editor so you can add some data columns. A column would correspond to a property in the class which represents a record from the table.
Now that the Order table is in place, repeat the process for the OrderItem table.
Once both tables exist, we need to "link" the tables together. That link would establish a relationship which can be either one-to-one or one-to-many. To do this, select the Order table and click the Table Schema and Permissions red button in the upper right corner.
Click the Add Relationship button.
In the popup that appears, you will need to create a property which will contain a collection of order item objects. Name that property "orderItems" (it is okay to make it plural here). On the right side of the popup select the OrderItem table. In the Multiplicity drop-down select Many.
Click Save. At this point the relationship is established.
To see it working you can either use the code generation module which will give you all the source code for working with the tables. Click the Code Generation icon. In the Android section, select either Eclipse or IDEA in the IDE block, then click the Java classes for defined data tables option. Click Download Project. Backendless will generate a ZIP file with the source code for the client-side classes that will let you perform a full CRUD (Create, Retrieve, Update, Delete) range of operations on your tables.
The documentation describes how to work with related data. For instance, see the approaches and API for retrieving related objects.
Things are simpler when it comes to the question of how to load objects created by a user. So we come to the second question:
How to load objects created by a user?
The approach described above works equally well for linking the built-in Users table with any other table. However, specifically with the Users table, that link/relationship is not necessary. The reason for this is Backendless automatically tags any created object with the ID of the "owner", that is the user who created the object. That "tag" can be seen with the special ownerId property in the Users table. To enable retrieval of the objects which belong to the user, we need to modify the security permissions for the table which contains the objects created by users:
Login to console, select your app and click the Data icon.
Select the table with the objects created by users.
Click the Table Security and Permissions red button in the upper right corner of the screen.
Click the Role Permissions menu item.
Locate the cell at the intersection of the Find column and the AuthenticatedUser row. Click the cell until you see a red cross.
Repeat the previous step for the intersection of the Find column and the NotAuthenticatedUser row.
At this point you restricted all access to your table for both authenticated and not-authenticated (guest) users. The next step will allow the owners to retrieve the objects which they created.
Click the Owner Policy menu item.
Click the cell in the Find column until there is a green check mark.
At this point when you call any of the Find methods on that table, Backendless will return only the objects which belong to the currently logged in user.

MVC and Entity Framework - inserts, updates, best practice

I'll try to be short and clear with this question.
We have an asp.net mvc app that uses entity framework 4.
Our business model is relatively straightforward:
We have an object (which corresponds to a table) called Photo(s).
That photos table has a handful of columns that match up to properties on the object.
Description,Title,Date etc.
It also has a number columns that reference foreign keys for other tables:
AuthorId,LicenseId etc...
The author and license tables are complex in their own right, with multiple fields (Title,Summary,Date etc.)
I have multiple clients using this application to view their photos. I would like each client to dictate what fields they see when viewing the photos, as well as what fields they see when editing those fields.
My thought is to have tables setup saying client-a should see Field1,Field2 and Field3 when viewing their photos - and client-b should see Field1,Field4 and Field5. But some of these fields are not simply columns in the main photos table, they may be fields in a child table. so Field1 might be: Table.Photos.Title -> which corresponds to an object as: Objects.Photo.title...
but Field3 might be: Table.Licenses.LicenseSummary -> which corresponds to an object as: Objects.Photo.License.LicenseSummary
I'm trying to figure out the methodology that we would use to have a very data driven environment so in the DB I can say, display this object/property (for viewing or editing) and then it would know how to map to whatever table it needs to pull that information. also, during editing... give it some way to pull a list of available values if it is that type of property, and not just a text field.
I'm looking for an example of what this might involve, our model is actually more complex than this, but this is just an idea of what we are trying to accomplish. I don't know if what I'm trying to do is normal, perhaps it involves reflection? This is a new area for me.
If the clients are defining their own custom fields, I would simply give them a Key/Value pairs table.
PhotoID FK
Key string
Value string
Display bool
Note that this essentially amounts to EAV, which comes with its own set of difficulties.
If it's just about permissions on existing fields, you need to capture that information:
PhotoID FK
ClientID FK
FieldName string
Display Bool
You can use this information to inhibit the display of fields in the View. The easiest way to do that would be to use a loop in the View itself, writing the field to the output only if Display is set to true.

DB grid : How to use a column of the current row of one as an index into another?

I am not sure if the question title is clear enough, please feel free to edit it.
Basically, I have two DB grids which reflect two database tables, each grid showing one.
When the user selects a row in the first table (let's call it oders), I want to update the second with details of any rows matching a column of the selected row of the first table.
Say, for instance that table orders has a column customer_id and I want to populate the second table (let's call it order_details) with details of all orders from that customer, one order per row.
I can connect up 2 # datasource, query and connection to the two TDbGrids, but I am stuck as to how to code order_details SQL.
The SQL for orders is just SELECT * from orders, but the other?
I want something like SELECT * from order_details WHERE cutomer_id=<orderQuery>.currentRow.FieldByName("customer_id").AsInteger - but I don't know how to do that ...
Can someone help me with some Delphi code?
Also, once I set up that relationship, will selecting a new row in the orders DB grid automatically update the order_details DB grid? Or do I need to add code for that.
P.s I know that there is no books tag anymore (more's the pity), but can someone recommend a good book which explains the fundamentals of programming DB aware controls? I obviously need one. Thanks
Use a parameterized query for the detail (child) database:
SELECT * FROM Order_Details od WHERE od.CustomerID = :CustomerID
Then set the child query's MasterSource to the parent (Order) datasource, and the MasterFields to CustomerID. (If there are multiple columns that link the two, separate them by ;, as in CustomerID;OrderNumber.)
Every time you scroll the parent (change the selected record in the parent DBGrid), the child query will be executed with the ID of the parent row passed as a parameter automatically.

Resources