0 votes

For our documents we have a field which contains a select list with the type of the document. For example: incoming files, outgoing files, document containing financial files etc.

When creating a new document I automatically want to add the category based on the chosen type. How can I make this possible?


asked in Partners by (219 points)

2 Answers

0 votes
Best answer

First of all, I assume you are using a version of Efficy 2014+ ?
I made some time to work it out, I used Efficy 10 SP2 fyi.

I created a lookup field F_TYPE on the documents entity and bounded it to a lookup with 2 entries. Only when the first type is selected, I want to activate the invoice category automatically.

  1. Invoices
  2. Other

The document type field is added to the form Standard: Edit Document in the main section. Important is that you specificy a new field definition ACTIVATECATEGORY for this F_TYPE field. This will be the mapping with the macro. Commit the form and logon again.

Customize the file macros/FormFieldsEditCustom.txt to specify this new ACTIVATECATEGORY definition:

    field.ACTIVATECATEGORY {[<%CreateEditButton(actioncode="CEB_RUN_SCRIPT5", action="javascript:EditStateWithScript(#EDITHANDLE, #BOOKMARK, 'CommonLibrary', 'ActivateCategory', '')")%>
    <%GetEdit("$FIELD$", type="LOOKUP", onchange="CebPerform('CEB_RUN_SCRIPT', 5)", data-placeholder="<%GetLabel('Select Value')%>...")%>]}

Customize the file serverscripts/CommonLibraryCustom.js:

var CONST = {
    "docuType": {
        "invoice": 1,
        "other": 2

function GetDocuCategoriesToActivate(editId) {
    var ds = Database.GetMasterDataSet(editId, 0);
    var type = ds.FieldByName("F_TYPE").asInteger;
    if (type === CONST.docuType.invoice) return ["DOCU$INVOICING"]; 
    return [];

function GetActiCategoriesToActivate(editId) {
    // idem dito docu, but maybe based on another lookup field?

 * Activate conditionally a category for the current edit context
 * Switch based on the entity what category needs to be activated
function ActivateCategory() {
    var editId = Request.ContextHandle();
    var entity = Database.GetEditEntity(editId); // ntDocu, ntActi...

    var categories = [];
    switch (entity) {
        case ntDocu: categories = GetDocuCategoriesToActivate(editId); break;
        case ntActi: categories = GetActiCategoriesToActivate(editId); break;

    for (var i=0, l=categories.length; i<l; i++) {
        Database.ActivateCategory(editId, categories[i]);

Select category, form will submit (no apply yet) and serverscript will activate category
Category Invoicing was activated by the server

So it is quite simple to achieve and I tried to make it generic, so you can use the same system easily for instance on the edit of a task/appointment, or opportunities etc... Just change the conditions for the mapping.

Hope it works at your side.


answered by (7.4k points)
selected by
thanks a lot! I will try this immediately tomorrow.
Great, works like a charm! Only thing I have to add now is if the document already contains a Category it should not be possible to add another one. Do you have a quick fix for this one? I think your solution should be added as standard addition to the functionality at edn.efficy.com?
You will have to check with Database.GetCategoryDataSet for each known category of the edit context if one is activated. There is no general "one category active" function.

We currently see EDN as a reference guide containing API methods and a limited amount of samples.

Overflow was added to store specific contributions like this one.
0 votes

There are two ways:

  1. You add client side Javascript code that on change of the category, performs a submit and executes a serverscript to activate the category, based on the selection. This works instantly and you could enforce required fields in the category. Use a combination of CreateEditButton and a CebPerform that will call a severscript "docu" containing the function "ActivateDocuCategory"

    <%CreateEditButton(actioncode="CEB_RUN_SCRIPT1", action="javascript:EditStateWithScript(#EDITHANDLE, #BOOKMARK, 'docu', 'ActivateDocuCategory', '')")%>
    CebPerform('CEBRUNSCRIPT', 1);

  2. Easier to achieve, but a bit too late imo, is to activate the category in the BeforeCommitDocu event.

I know it's not a complete working sample, but it contains the layout of how you can achieve it.

answered by (7.4k points)
Welcome to Efficy Overflow, where you can ask questions and receive answers from other members of the community.
1,248 questions
1,518 answers
328 users