How to find a table name by ID in Dynamics AX - axapta

Each table in the AOT has an ID, how can I discover the table name given an ID?

Looking at the SQL dictironary is really the correct method.
Search for the line with the FieldId equal to 0.
Using TSQL this will tell the name of the table for tableid 505
select NAME
from SQLDICTIONARY
where TABLEID = 505
and FIELDID = 0

From X++, use the tableId2Name function.
From the GUI, choose Tools/Development tools/Application objects/Application objects and filter for a recordType of TableInternalHeader and a parentId of the table id you are looking for.
Or in the AOT, right click on Tables and choose Find. On the Name & Location tab, set Search to All nodes. On the Properties tab click Selected next to ID and fill in the table id in the Range field.

I dont'know if this is your answer,
if you want to give the TableName with his ID, you can use
the method:
str tableId2Name(int _tableid)
For example:
If YourTable has ID :123456 ;
use method
tableId2PName(123456)
will return the str name YourTable.
info(strFmt("%1" , tableId2PName(123456))); -> VideoStamp the name.
I used the info in
https://msdn.microsoft.com/en-us/library/aa498759.aspx
I hope to useful , greetings!

If you need AX system table name you can use tableId2name or DictTable.name method.
If you need SQL table name you shoud use DictTable.name method with first argument of DbBackend::Sql
Example:
print new DictTable(tableNum(DirPartyTable)).name(DbBackend::Sql);
print new DictTable(tableNum(OMOperatingUnit)).name(DbBackend::Sql);
pause;
// result:
// DIRPARTYTABLE
// DIRPARTYTABLE

Or you can try:
select Name, AxId
from MicrosoftDynamicsAX_model.dbo.ModelElement (nolock)
where ElementType = 44
order by AxId

In the AOT, go to the System Documentation node.
In the Tables node, find SqlDictionary and open it with the table browser.
Filter the column TabId with your ID.

In the AOT, go to the System Documentation node. In the Tables node, find SqlDictionary and right click and open it with the table browser. Filter the column TabId with your ID and fieldid == 0, his will give you the name of the table.

Easiest way:
Create a project (not necessary but easier to delete later)
Add a new view to your project
Add the data source SqlSyncInfo
Drag the fields ID, MessageType, SyncTable, TableName, etc to field
Open the view
It provides all the table names and their respective IDs. Just filter what you want. If you know the table ID, search for that. If you know the table name, search for that.

Related

Ax2012 - get the value of accountNum in the selected row in a grid

In the form cutslistepage , i want to get the value of accountNum of the selected row in grid and passe it to another form
i have try that :
int64 recordsCount;
recordsCount = CustTable_ds.recordsMarked().lastIndex();
// CustTable = CustTable_ds.getFirst(1);
If you want to retrieve the CustTable record, check the CustTableListPageInteraction class.
In the selectionChanged method, it has the following code:
custTable = CustTable::findRecId(this.listPage().activeRecord(queryDataSourceStr(CustTableListPage, CustTable)).RecId);
This is how you can retrieve the record. But since it is already done, you can simply use the custTable variable that is already declared in the class declaration.
Side note: if you have an other form that is opened from the list page, it should automatically be filtered based on the relations between the data sources of the form. So you might be searching for a solution for a problem you shouldn't have. For example create a form that has a data source with a relation to the CustTable table on it and it should create a dynaink between the list page and your form, filtering the records for that customer.
If only one record is selected you can do:
info(CustTable_ds.accountNum);
Otherwise, if more than one record is selected you need to do something like:
custTable = CustTable_ds.getFirst(true);
while (custTable)
{
info(custTable.accountNum);
custTable = CustTable_ds.getNext();
}

How to use SQL Server 2008 stored procedure in asp.net mvc

I have created a simple stored procedure in SQL Server 2008 as:
CREATE PROCEDURE viewPosts
AS
SELECT * FROM dbo.Post
Now, I have no idea how to use it in controller's action, I have a database object which is:
entities db = new entities();
Kindly tell me how to use stored procedure with this database object in Entity Framework.
For Details check this link:
http://www.entityframeworktutorial.net/data-read-using-stored-procedure.aspx
Hope this will help you.
See article about 30% in:
In the designer, right click on the entity and select Stored Procedure mapping.
Click and then click the drop down arrow that appears. This exposes the list of all Functions found in the DB metadata.
Select Procedure from the list. The designer will do its best job of matching the stored procedure’s parameters with the entity properties using the names. In this case, since all of the property names match the parameter names, it maps every one correctly so you don’t need to make any changes. Note: The designer is not able to automatically detect the name of the field being returned.
Under the Result Column Bindings section, click and enter variable name. The designer should automatically select the entity key property for this final mapping.
The following code is what I use to initialize the stored procedure, then obtain the result into variable returnedResult, which in this case is the record id of a newly created record.
SqlParameter paramResult = new SqlParameter("#Result", -1);
paramResult.Direction = System.Data.ParameterDirection.Output;
var addParameters = new List<SqlParameter>
{
new SqlParameter("#JobID", EvalModel.JobID),
new SqlParameter("#SafetyEvaluator", EvalModel.SafetyEvaluator),
new SqlParameter("#EvaluationGuid", EvalModel.EvaluationGuid),
new SqlParameter("#EvalType", EvalModel.EvalType),
new SqlParameter("#Completion", EvalModel.Completion),
new SqlParameter("#ManPower", EvalModel.ManPower),
new SqlParameter("#EDate", EvalModel.EDate),
new SqlParameter("#CreateDate", EvalModel.CreateDate),
new SqlParameter("#Deficiency", EvalModel.Deficiency.HasValue ? EvalModel.Deficiency.Value : 0),
new SqlParameter("#DeficiencyComment", EvalModel.DeficiencyComment != null ? EvalModel.DeficiencyComment : ""),
new SqlParameter("#Traffic", EvalModel.Traffic.HasValue ? EvalModel.Traffic.Value : 0),
paramResult
};
// Stored procedure name is AddEval
context.Database.ExecuteSqlCommand("AddEval #JobID, #SafetyEvaluator, #EvaluationGuid, #EvalType, #Completion, #ManPower, #EDate, #CreateDate, #Deficiency, #DeficiencyComment, #Traffic, #Result OUTPUT", addParameters.ToArray());
var returnedResult = paramResult.Value;
NewEvaluationID = Convert.ToInt32(returnedResult);

Foreign key shows wrong field in dropdownlis in dynamic data

Foreign key fields in Dynamic Data show the next char field of the child table in dropdownlist. How can I tell it to show another field?
Assume these tables:
Personnel(PKPersonnelID, PersonnelName, FKDepartmentID)
Department(PKDepartmentID, Description, Department)
FKDepartmentID in Personnel table is a foreign key to Department table. When I want to insert new record to Personnel, Dynamic Data shows me a DropDownList for FKDepartmentID. In this DropDownList the values from Description field are displayed(As I recognized it shows the first char field after the primary key). But I want to show Department field values.
The code where you are binding the data with the drop down list, can you please show it over here, let say your drop down list Id is drpDepartment, than make your binding like:
drpDepartment.DataTextField = "Department";
drpDepartment.DataValueField = "PKDepartmentID";
drpDepartment.DataSource = YOURCOLLECTION OR DATASOURCE;
drpDepartment.DataBind();

Enter default values into FieldContainer

I am using a Field Container to enter a new Contact information, and I would like to populate some of the fields with values.
I can do this for normal fields like Phone and LastName, but ti does not work for lookup fields like ReportsTo and Account.
This is th code I am using:-
var acc:DynamicEntity = new itemClass("Contact");
acc.Phone="8888";
acc.LastName="Nieddu Srl"
acc.ReportsTo ="0012000000RsJYb"
acc.Account="test"
_createFieldContainer.render(acc)
Is there any way to populate a lookup field with a default value when the field container is called??
Thanks
Roy
I can see a couple of issues here:
You need 'Id' on the end of your lookup fields - i.e. ReportsToId, AccountId
You need to supply a real object Id for Account.
So your code would look something like:
var acc:DynamicEntity = new itemClass("Contact");
acc.Phone = "8888";
acc.LastName = "Nieddu Srl";
acc.ReportsToId = "0012000000RsJYb";
acc.AccountId = "00123400000RHEG";
_createFieldContainer.render(acc);

Asp .Net LINQ to SQL Databinding, do a "lookup" without a lookup table?

Say I have an Employee table. Each Employee has a unique id. One of the columns in the table is ManagerId, which corresponds to another Employee. When binding an Employee's data to a GridView, I want to display the Manager's name, not their Id. If I had a lookup table for Mangers I could just do <%# Eval("lu_Managers.ManagerName") %>, but I don't have such a table, nor do I want to make one/keep track of it/update it everytime a new manager is added or removed.
Currently in the OnRowDataBound I call e.Row.Cells[1].Text = getFullNameFromEmployeeId(Convert.ToInt32(e.Row.Cells[1].Text)); which seems fairly messy to me.
Is there a way to do this without using the codebehind? Or would that be less efficient than what I have now?
You need to join the Employee table again for the manager
SELECT
Employee.*,
Manager.FirstName As ManagerName
FROM
tblEmployee As Employee
JOIN tblEmployee As Manager
ON Employee.ManagerID = Manager.pkEmployeeID
EDIT:
Which can be easily translated into LINQ:
var q =
from employee in db.tblEmployee
join manager in db.tblEmployee
on employee.ManagerID equals manager.pkEmployeeID
select new
{
Employee = employee,
ManagerName = manager.FirstName
};
OK, if there a unary relationship setup? If a relationship, Employee would have an Employee property that points to that manager, so you could reference with Employee.EmployeeName. Otherwise, if no explicit navigation property, you would have to use a query from code-behind.
HTH.

Resources