+1 vote

Hello Efficy Team,

The question is quite simple. What is exactly a "tableViewIndex" ?
We can find the tableViewIndex in multiple serverJs function, as parameters.

I guess it is the "id of the table" from the sys_tableviews. Is it well the table id returned by the function Efficy.entityCatalog.tableIdFromEntityDetail (and some other functions) ?

Then, how to use it ? Can you give us concrete exemple of cases where we should use this parameter with another value than 0 ?

Thanks in advance for the enlightenment,

Loïc

asked in WorkFlow / Serverscript by (416 points)

2 Answers

0 votes

A tableViewIndex is the index of a dataset related to the current context. It is possible to get a detail dataset or a category dataset by providing the corresponding index to the getMasterDataset operation. But that is not a good idea to use it like that, it will make the code less readable.

Actually, tableViewIndex is for the majority of the time just 0. In JSON RPC, you can even omit the tableview in the update function of an entity.

The only place where a tableViewIndex is to be used is in a mutual linking operation like COMP_COMP. Then you can set the two values for RELATION.

function setCompCompRelation(editCompComp, inserted) {
var dsComp = Database.getMasterDataSet(editCompComp, 0);
dsComp.edit;
dsComp.fieldByName("RELATION").asInteger = 20;

dsComp1 = Database.getMasterDataSet(editCompComp, 1);
dsComp1.edit;
dsComp1.fieldByName("RELATION").asInteger = 17; 
}
answered by (6.4k points)
0 votes

Kristof's answer is very good, below some addition information.

In Efficy the data access to a table is done with so-called "table views" which are defined in SYS_TABLEVIEWS. This system table contains a number of fields to define which SQL select is performed on the table (with filters or join clauses).

When you open an edit or consult context for an entity, you open a so-called "entity view" which contains a collection of these table views. They are defined in SYS_ENTITYVIEWS.
The tableViewIndex refers to the order of the table views in this collection.

For example the entity view for editing a Contact is called ContEdit and contains 3 table views: Cont (tableViewIndex = 0), Cont_User (tableViewIndex = 1) and Cont_Comp (tableViewIndex = 2).

For most edit contexts there is the main or "master" entity (tableViewIndex 0) and a number of "detail" entities which are usually referred to by name. For example, for ContEdit we retrieve the users linked to the contact by GetDetailDataSet(ntUser) and the linked companies by GetDetailDataSet(ntComp).

Only when the "master" or "detail" concept doesn't apply, the "tableViewIndex" approach becomes useful. For example, when editing a Company-Company relation using the "Comp_CompEdit" entity view you'll find two table views for modifying the bidirectional relationship. There is no "detail" in this entity view, and you can only refer to the table views by means of their tableViewIndex.

answered by (756 points)
1,129 questions
1,381 answers
1,642 comments
320 users