+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,


asked in WorkFlow / Serverscript by (531 points)

3 Answers

+1 vote

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.fieldByName("RELATION").asInteger = 20;

dsComp1 = Database.getMasterDataSet(editCompComp, 1);
dsComp1.fieldByName("RELATION").asInteger = 17; 
answered by (7.4k points)
+1 vote

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 (1.2k points)
0 votes

Here's an example in a custom where I had to make an update of an existing document based on another one (field values, links but not files):

// Copy main data (0) and all details, except files (2)

Efficy.CopyFromExisting(d, templateDocumentKey, 0, 1);
Efficy.CopyFromExisting(d, templateDocumentKey, 3);

answered by (239 points)
1,246 questions
1,517 answers
328 users