Accessing grandchildren with tokens - Forum - Rollbase - Progress Community

Accessing grandchildren with tokens

 Forum

Accessing grandchildren with tokens

  • I would like to access a related grandchild through template script. For example, I have a 'Sale' record that has related 'Sale Product' records and those are related to a 'Product' record. In other words, the 'Sale' object is the fact table, the 'Sale Product' object is the "factless fact" table and the 'Product' object is the lookup table. From the 'Sale' page, I'd like to navigate to a Field of the Products. Is this possible? From the Template Helper, I can only see Fields of a child, not a grandchild. So instead of {!R123.FieldA}, I would like to use {!R123.R124.FieldB}.
  • I could conceive of solving this one by using the following api calls...



    rbv_api.getRelatedIds ("R123", SaleId)

    ...for each SaleProductId in array...



    &nbsp&nbsp rbv_api.getRelatedIds ("R124", SaleProductId)

    &nbsp&nbsp ...for each ProductId in array...



    &nbsp&nbsp&nbsp&nbsp&nbsp rbv_api.getFieldValue("Product", ProductId, "FieldB")







    Is the performance of API calls the same as using tokens? Is one method resolved at runtime, and another resolved at design time (or at least translated into Java via Rhino at design time)? Is there a difference, or under the hood, are tokens and api calls doing the same thing, so there is no performance difference (assuming you are logically doing the same operation)?



    By the way, Salesforce.com handles it like this.
  • I would recommend to use tokens - that will be a bit faster.
  • Hello Bob,



    I have confirmed that Rollbase tokens perform faster than Rollbase API in terms of data manipulation. Please let me know if there's any other questions you'd like me to assist you with.



    Thanks,

    Corey Prak
  • Thanks for your response. Good to know that tokens perform faster. Can you comment on how to access a grandchild via tokens?
  • Hello,



    As far as I know, you cannot access childs using tokens. The token exists but only returns one of the childs records which seems to be the latest modified child (which in most cases serves no purpose).



    You can use tokens to access father and grandfather IDs of a records. If you want to go beyond that (grand-grandfather), you have to use api functions such as:

    - rbv_api.getRelatedIds(...)[0]

    - rbv_api.selectNumber(...)

    - rbv_api.selectQuery(...)[0][x]



    For instance:

    - Record ID : {!id}

    - Father ID : {!R123#id}

    - Grandfather ID : {!R123.R124#id}

    - Grand-Grandfather ID : rbv_api.getRelatedIds("R125", {!R123.R124#id})[0]

    etc.



    To retrieve childs, you can only achieve it using api functions

    - rbv_api.getRelatedIds(...)

    - rbv_api.selectQuery(...)

    and loop through to results to then retrieve grandchilds etc. (Like in your example above).
  • Hi Romain,

    Thanks for your response. You can retrieve all children using tokens. You just need to place the child token within a LOOP_BEGIN token and a LOOP_END token, which you can find in the Template Helper. If you do not place it within these, you will only get one entry.



    {!#LOOP_BEGIN.R123#555}

    {!R123.fieldA#text}

    {!#LOOP_END.R123}



    I'd still like to know how to retrieve a grandchild with tokens (as that is apparently faster) however. Anyone?

  • Unfortunately we don't have template syntax for nested loops or grandchildren access. You can try server-side API, although this may be less intuitive.