+8 votes

Hello Efficy Team,

Because I would like that the Overflow become the source of knowledge for all our daily customisation, I took some time to put in a post a "tricky" customisation. This kind of demands are often asked by customer and we don't always respond to it the right way.

Create a custom relation form between Project and Contacts, using a K_RELATION

First step : add a KRELATION in PPROJCONT

For the context: Efficy is used to manage the leasing of products. Each product can be lease to the same person at different moment. There is always one contact for a single period, but the same contact could lease the same product (or collection of product) multiple time. This is why we use project and we need a K_RELATION.

enter image description here

Adding the KRELATION is quite simple. Just add the field "KRELATION" in the sysfields with DbEditor (with almost the same parameters as the KPROJECT and the K_CONTACT).

Then make an apply structure.

Second (very easy) step : creating the form in the designer

This is the easiest part. Use the designer to create a new form on the table "PROJ_CONT". Add the field that you've created.

Don't forget to write the K_FORM somewhere, this will be useful for the next step.

Add the "modify relation" button and show the form

2 macros need to be modified :


DetailMenu.Proj.Cont {[<%GetPopupMenu(id="detail-menu", class="has-icons small", ulargs='data-channel="detailmenu"', count="4",
     text1="Edit #DETAIL", image1="i-edit",
     text2="Edit Relation", image2="i-link", onlinehelp2="e110_linkitems",
     text3="Delete Relation", image3="i-delete", onlinehelp3="e110_linkitems",
     text4="Add Call Back Task", image4="i-callback",  onlinehelp4="e110_createcallbacktasks",

Then you use the K_FORM of your new "custom Project - Contact"


RelationSectionsForm.Proj.Cont {[2]}

Editing the "good" relation

If you tested so far, you should see that you can "edit the relation" and your form is showing. But unfortunately, it does not show you current relation. Because we didn't specified witch relation need to be updated.

We first need to retrieve the KRELATION. For that, we'll duplicate the "KMASTER=0;KDETAIL=11" and we'll create a new "KMASTER=20;K_DETAIL=11"

We just add the K_RELATION on the column "by default" retrieved :

enter image description here

Then we'll overload the default "consult queries" for the relation "PROJ_CONT" :

MacroConsultCustom :

ConsultQueries.Proj.Cont {[
<%RunQuery(id="MainComp", SQL="select C.K_COMPANY, C.NAME from <#table name='PROJ_COMP'> PC, <#table name='COMPANIES'> C
    where C.K_COMPANY = PC.K_COMPANY and PC.K_PROJECT=:param1 and PC.MAIN=1", param1="#K", store="1")%>
<%RunQuery(id="MainCont", SQL="select C.K_CONTACT, C.NAME, C.MIDDLENAME, C.FIRSTNAME from <#table name='PROJ_CONT'> PC, <#table name='CONTACTS'> C
    where C.K_CONTACT = PC.K_CONTACT and PC.K_PROJECT=:param1 and PC.MAIN=1", param1="#K", store="2")%>

<%RunQuery(id="ListCont", MASTER="20", DETAIL="11", param1="%%GetKey()", mainquery="true")%> ]}

We also need to change the "{dropdownKey}" argument passed by our detailMenu (edited before). Efficy know the relation to edit by following this rule : "detailKey_relationKey". To do this, we'll overload the "MENU" definition, with this new rule :

MacroConsultCustom :


GridColumnCustom : 

th.RELATIONMENU {[<th class="icon-cell hide-for-print"> </th>]}
td.RELATIONMENU {[<td class="menu icon-cell hide-for-print"><span class="dropdown no-pip i-menu small" hello data-dropdown="detail-menu" data-args="<#F=K_CONTACT;context=ATTR>_<#F=K_RELATION;context=ATTR>"></span></td>]} 

Then, ... it is done ! You'll be able to Edit the relation between project and contact, starting from the project. In my specific case it wasn't asked to do it starting from the contact itself but it wouldn't be hard to modify.

I hope it help you in the future,


asked in Efficy/ Client side by (531 points)

Please log in or register to answer this question.

1,248 questions
1,518 answers
328 users