Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Mapping of related fields with criteria


I need some help with a map criteria

I have 2 tables that are mapped, Produkt og Modul. They are joined in a third table, modul_produkt. So one module can belong to several products. My problem is that the second map (the modul map) I need to have a criteria depending on the produkt choosed in the first Map (the produkt map). I have tried with a t2.addcriteria as you can see below. When 2 is hardcoded as the value it works as it should. But this value should be the from the first map.

Any suggestions?

SearchEngine t;
t.addOrder("y_produkt.x_produkt", true);
for (t.execute(); !t.eof();
map.insert("id", t.getField(0));
map.insert("value", t.getField(1));
dd.setFieldValue("addNode", map);

map.insert("label", "Modul");
dd.setFieldValue("addLabel", map);
SearchEngine t2;
t2.addOrder("y_modul_produkt.x_modul.x_name", true);
//t2.addCriteria("y_modul_produkt.x_produkt", "Equals", "2", "And", 0);
for (t2.execute(); !t2.eof();
map.insert("id", t2.getField(1));
map.insert("value", t2.getField(2));
map.insert("parent", t2.getField(0));
dd.setFieldValue("addNode", map);

Hi Ingar, not exactly sure if I understand what you want to do here, but...

To get the value from the first map you could do something like this;

Integer value = map.get("id").toInteger();

and then use that in your criteria like this;

t2.addCriteria("y_modul_produk.x_produkt", "equals", value.toString());

But, note that the first map is filled by looping over all rows in the y_produkt table, but it will only contain info from the last row it found. This doesn't feel right.

What kind of HtmlElement is dd?

By: Frode Lillerud 23 Apr 2017