Relationship fields access through scripting

Posted by rzanardo on 20-Jun-2017 07:32

Hi everyone.

I'm "recreating" an old budget system that was developed with Ruby On Rails, with Rollbase, and I'm trying to create a HTML table to display some data. I couldn't find a way to use Rollbase's default list views or anything else, because these data has a very specific pattern.

I have some objects related something like this, to exemplify:

They're all "one-to-one" relationships, let's say -> Invoice -> Contract -> Bank Details

I create an invoice, that has a contract, that's linked to a "bank details" object.

The relationship works well, no problem with that, but I'm trying to make a document template to print this invoice in the correct way that our company uses.

But I've noticed, that Rollbase's helpers, in the new document's template screen (invoice object), for instance, the "Related Contract", with which I can access all of its fields and values... the related contract, in turn, shows the "field" or "linkup" to the bank details, I don't get it right, because I just can't access the "Bank Details" object's values in any way.

To exemplify a little what I'm doing :

To access the "END DATE" field from the Contract related to the invoice object : {!R353905312.end_date}

To access the "BANK DETAIL" from the Contract related to the invoice object : {!R353905312.R353905254#id}
The problem is, if I remove the #id, or replace it with ANYTHING else, it just won't bring me any value.

I'm having trouble to understand this rollbase format, since I'm used to "default database development", which I can relate and access anything by putting "dots" (.) and the fields names, I think I just can't access the fields of a "3rd level" related field, from the "1st", like in the example above.

The solution I could find was to create Related Fields of the Bank Details Object, in the Contract Object, to keep a "path" to access these values, but it just didn't seemed like it was the right way.

Is there any other solution, or did I do it right?

Thanks in advance, everyone.

Posted by Shiva Duriseati on 23-Jun-2017 01:47

Hi,

You can use EVAL block which can retrieve the values from "BankDetails" object. Like you said creating related fields in "Contract" and then accessing them from "Invoice" would also work ,but it is not recommended because when you add few more fields to "BankDetails" object again you have to add them as related field in Contract which will be a complex task.

Please look at sample example where we can access "bankdetails" by passing id using "related contract" from token helper in document template of "Invoice" object.

Example:

If you are creating a document template of type "HTML"

<p>Name of the bank is<p>: <b>#EVAL[

var a=rbv_api.selectQuery("SELECT name FROM BankDetails where id={!R60150413.R60150424#id}", 10);
return a[0][0];
]<b>


Please note you can use EVAL block in text or xml files also this function has to return some string value. Hope this helps.

Regards,
Shiva

All Replies

Posted by Shiva Duriseati on 23-Jun-2017 01:47

Hi,

You can use EVAL block which can retrieve the values from "BankDetails" object. Like you said creating related fields in "Contract" and then accessing them from "Invoice" would also work ,but it is not recommended because when you add few more fields to "BankDetails" object again you have to add them as related field in Contract which will be a complex task.

Please look at sample example where we can access "bankdetails" by passing id using "related contract" from token helper in document template of "Invoice" object.

Example:

If you are creating a document template of type "HTML"

<p>Name of the bank is<p>: <b>#EVAL[

var a=rbv_api.selectQuery("SELECT name FROM BankDetails where id={!R60150413.R60150424#id}", 10);
return a[0][0];
]<b>


Please note you can use EVAL block in text or xml files also this function has to return some string value. Hope this helps.

Regards,
Shiva

Posted by rzanardo on 23-Jun-2017 13:03

Hi Shiva!

Your answer was absolutely useful and it solved my 'problem'.

Things will be much easier now, thank you very much!

This thread is closed