Accessing grandchildren with tokens

Posted by Rollbase User on 10-Sep-2013 20:41

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}.

All Replies

Posted by Admin on 10-Sep-2013 21:44

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.

Posted by Admin on 11-Sep-2013 12:24

I would recommend to use tokens - that will be a bit faster.

Posted by Admin on 11-Sep-2013 13:09

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

Posted by Admin on 11-Sep-2013 15:35

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

Posted by Admin on 12-Sep-2013 06:54

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).

Posted by Admin on 12-Sep-2013 21:21

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?

Posted by Admin on 13-Sep-2013 12:07

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.

This thread is closed