Having problem in using Template Field. - Forum - Rollbase - Progress Community

Having problem in using Template Field.

 Forum

Having problem in using Template Field.

This question is not answered

I have 3 Objects in this scenario. Object A has one-to-many relationships with Object B and Object C. For example, Object B has record b1, b2 and b3, so does Object C have c1, c2 and c3. All these records are referred in a record of Object A. 

I intend to create a Template Field of Object A which is the concatenation of the record name/id of Object B and C. In other words, 9 Fields could be created dynamically, like b1c1, b1c2, etc. Since I could not use nested loops in the Template Editor, How could I make this happen? 

I also tried to use server-side query APIs, but I don't know the syntax of writing logic in the Template. For instance, can I use JavaScript For Loop in it, or can I assign the return value of a select query to an array in the Template? 

Thanks in advance~

 

All Replies
  • I hope I am not misunderstanding your need (one-to-many relationship), but it seems to me you are trying to build this relationship the wrong way around.  The "child" records such as b1,b2, b3 and c1,c2,c3 should each have one simple field that links to a1 (foreign key).  Then there is no need for a list of indefinite length on the "A" records.

  • Sorry for the inaccurate description. It's actually many-to-many, "b" and "c" record could be used multiple times in many "a" records as well. However, I don't need to create any View on the B or C side. A Object just simply needs a formula field that is the combination of  all "b" and "c" records' name

    I wrote the following code in the Formula Field definition editor, the Query and Loop is alright at the moment.

    /* ******************************* */

    var b_2D = rbv_api.selectQuery("SELECT name FROM OBJ_B ORDER BY createdAt ASC", 100);

    var c_2D = rbv_api.selectQuery("SELECT name FROM OBJ_C WHERE x_x_x#code='XXX' ORDER BY createdAt ASC", 100);

    var b = new Array();
    for(var i=0; i<b_2D.length; i++){
    b[i] = b_2D[i][0];
    }

    var c = new Array();
    for(var i=0; i<c_2D.length; i++){
    c[i] = c_2D[i][0];
    }

    var formBlocks = [b.length];
    for(var i=0; i<b.length; i++){
    formBlocks[i] = new Array(c.length);
    }

    for(var sc=0; sc<b.length; sc++){
    for(var sp=0; sp<c.length; sp++){
    formBlocks[sc][sp] = b[sc] + "|" + c[sp];
    }
    }

    return formBlocks;

    /* ******************************* */

    My question is, Is it possible to retrieve all elements in the 2-D Array (formBlocks) from the "Edit this Page",

    although it can only return one particular element, like forBlock[0][0] to the Page Editor.

    My target is to dynamically create fields of Object A, and each field's name is one of  the combination of all names of  Object B's and C's records.   

    Many thanks!