How to get value of linked table

Hi there,

I have schema Projects where is column ID. I have created link to this schema (Projects) in another schema Documents.

At Documents I have tried JS like doo.model.<[Documents (doc_ToProject)]>.value; but it will return [object object].

How should I handle this?

Hi Thomas,
in the linked values, there is an object based on the destination schema. Usually, I put
console.log(doo.model.<[Documents (doc_ToProject)]>.value)
to check the structure in the console, so I can use it in my script.
Can that work for you?
Regards
Michal

Hello, thank you for an answer.

Well console log works in right way, but I still have no idea how can I get value of one column from linked schema.

Problem is, when I just create new row in schema Documents and then I want to choose row from Projects (which is linked/related to Documents) so I have there two columns (ID and Name). Then, when i pick whatever row and use this JS:

var CisloPrirazeni = doo.model.<[K zakƔzce (dokumenty_kZakazce)]>.value;
doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = CisloPrirazeni;

so it will be saved just as [object object], probably cosā€™ of an array or something?

So I would like to know how to set var CisloPrirazenĆ­ and save just that value what I want to (ID).

Note: In schema Projects I have set Schema item internal name and put on Include in lookup selected value at both columns (ID even NAME).

Hi Thomas,
When you do
console.log(doo.model.<[K zakƔzce (dokumenty_kZakazce)]>.value)
in a Tab ā€œOn Model Changeā€
you should receive the object with its properties into a console output window (F12).
Letā€™s say, that you can see something like;

{
    id: "6f94bf6e-800e-4f13-96a3-c18a310e7e82"
    xhivovk02h: 'myId',
    weoriuklkdf: 'Name of the XY',
...
    _$$changed: true
    _$$originalId: null
...
}

It depends on your internal property names (you are able to change them in schema items).

Then, when you know the name of your property, you are able to use it like this:
doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = CisloPrirazeni.xhivovk02h

In case my explanation is not clear, can you append the output from
console.log(doo.model.<[K zakƔzce (dokumenty_kZakazce)]>.value)
to the question, please?

Or, you can contact me directly and we can arrange a call :wink:
michal.cumpelik@tabidoo.cloud
Regards
Michal

I have used console.log(doo.model.<[K zakƔzce (dokumenty_kZakazce)]>.value)

In console I see this:value

So I have tried doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = CisloPrirazeni.zakazky_id;

but still getting error

Custom script running error: TypeError: Cannot read property ā€˜zakazky_idā€™ of undefined

Did I something wrong?

Well now I seeā€¦ It works - but getting error cosā€™ value is null with new record.

Great!
So I guess you changed that to something like

var CisloPrirazeni = doo.model.<[K zakƔzce (dokumenty_kZakazce)]>.value;
if (CisloPrirazeni)
    doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = CisloPrirazeni.zakazky_id;
else
    doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = null;

or
doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = (CisloPrirazeni ? CisloPrirazeni.zakazky_id : null);

I did not check the syntax of my examples :slight_smile:

1 Like

The first metod works for me.

Thank you micu :slight_smile:

Hi @micu,
I tried to insert these instructions as you wrote, to assign a field of a linked table, but it generates an error, where am I wrong? The name of the field is ā€œCONVENTIONEDā€:

var cnv= doo.model.<[CONVENZIONATO (convenz)]>.value; //Linked Field
doo.model.<[CNV (xpdyokzm99)]>.value == ā€˜ā€™; // if true
doo.model.<[CNV (xpdyokzm99)]>.value = cnv.CONVENZIONATO;

ERROR: undefined is not an object (evaluating ā€˜cnv.CONVENZIONATOā€™)

Thank You

Hi,
I do not understand this line:

doo.model.<[CNV (xpdyokzm99)]>.value == ā€˜ā€™; // if true 

Do you want to compare or assign? And the ā€˜ā€™ does not look as valid apostrophe either.

I donā€™t know the type of CONVENZIONATO . String?
In case ā€˜cnvā€™ā€™ is a linked table, the value is JSON object. Not a simple value. Try

console.log(cnv)

and check what is written in the console during edit.
Regards
Michal

PS: Check setValue() in our help

Thanks for the answer @micu , but I have not come to the head and opening console.log on the browser I get continuous errors.
What I want to achieve is that if a TEXT type ā€œAā€ field is NULL or EMPTY it must fill it with the value of a linked field ā€œBā€ that it contains (field1, field2, field3 of type text). More precisely, if the condition is satisfied, the field ā€œAā€ must be = ā€œ(field2)ā€ of the linked table ā€œBā€. I hope I was clearer.

doo.model.<[CNV (xpdyokzm99)]>.value == ā€˜ā€™; // if true Thank you
This works for me, check if the text field is empty, syntax is correct

Thanks for the example you will give me. Greetings

It is pretty dificult just without the case. I would say that something like this can work:

var cnv= doo.model.<[B (link)]>.value;
console.log(cnv); // check properties during model change in the real form in the console, delete later
if (!doo.model.<[A (text)]>.value && cnv.value) {
   
   doo.model.<[A (text)]>.value = cnv.field1;
}

Hi @micu , I just got it another way like this:

var cnv= doo.model.<[CONVENZIONATO (convenz)]>.value;
doo.model.<[CNV (xpdyokzm99)]>.value == ā€˜ā€™;
doo.model.<[CNV (xpdyokzm99)]>.value=cnv.rag_sociale;
It works perfectly
Obviously rag_sociale is the name of the internal field that I assigned in the linked schema!

Now Iā€™ll also check your code, then Iā€™ll let you know if it works. Thank you very much.