How to access values from records in db?

Hello!

 

I've been searching for documentation on how to access data in a column, from the database, but to no avail. To give you some sort of background, my Product object has a detail called Collateral. Users can add more collaterals - each having an allocation percentage. What I need is to create a function that gets from the database the allocation percentage of each Collateral added to the Product. How can I implement this with javascript?

Example: Product1 has 3 Collaterals added: Coll1, Coll2, Coll3.

How can I get, for Product1 the allocation percentage of each Collateral?

Also, where could I check more documentation on the available methods? For example, asyncValidate for javascript?

Like 1

Like

4 comments

Hi Maria,

 

You need to use ESQ to get the data from some record in the detail related to the section. In this case you need to get the Id of the current main record (where the detail is located) by using for example:

var currentRecordId = this.get("Id");

and then in the ESQ filter you need to specify this Id in the filtration ("CollateralsInProduct" should be replaced with your detail object code, "CollateralValue" should be replaced with the code of the column in the "CollateralsInProduct" object where the actual values are stored, "ProductId" should be replaced with the code of the column that connects you detail to the main product record):

var esq = Ext.create("Terrasoft.EntitySchemaQuery", {
    rootSchemaName: "CollateralsInProduct"
});
esq.addColumn("CollateralValue");
var esqFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "ProductId", currentRecordId);
esq.getEntityCollection(function (result) {
    if (result.success) {
        result.collection.each(function (item) {
            /* Process the collection elements. */
        });
    }
}, this);

As for more documentation on basic methods like asyncValidate - unfortunately we have none suitable one where all the methods are described. I will ask our Academy team to create this article where all the available methods and properties are described so anyone could easily search data they need, thank you for this suggestion.

Hi Maria,

I have an article outlining a simple place to start with EntitySchemaQuery (to query the database from client-side code) here: https://customerfx.com/article/an-introduction-to-performing-client-sid…

Also an article on using asyncValidate here: https://customerfx.com/article/asynchonous-validation-on-pages-in-creat…

Hope this helps get you started. 

Ryan

Oleg Drobina,

Thank you, your answer enlightened me very much. Though I have some trouble accessing the id of the product. 

Based on what you explained, 

In this case you need to get the Id of the current main record (where the detail is located) by using for example:

 var currentRecordId = this.get("Id");

I understood that through this line of code I am accessing the id of the product to which my collaterals are added. But by logging this id to the console, I noticed that each time it comes different. Is this the id of each collateral that I am adding? How can I get to the id of the product? That's what I am supposed to do, right?

Thank you so much for the attention.

For me, I usely add a debugger to the code. Then examine "this" In the console to see what values are already available.

Show all comments