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?

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:

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.

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;
    doo.model.<[Přidruženo k (dokumenty_PridruzenK)]>.value = null;

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:

The first metod works for me.

Thank you micu :slight_smile: