How to access a value in a detail table for a conditional script

I need to access the value of a field that is in a detail table for a conditional script. The field exists but i get an “unknown field” in the script editor. I have copied the script below. I am sure it just can’t find the field but I cannot figure out the correct statement to use. I have tried record.field, record.detail, etc.

The condition relies on two values so I am using a switch statement.

Thanks!

var text;
var itemCheck;

if (record.fields[“line_items”] == “1”) {
itemCheck = “1”;
} else{
itemCheck = “2”;
}

switch (itemCheck){
case “1” :
if (record.fields[“kostenart_id”] == “1048”) {
text = “varText1”;
}
else if (record.fields[“kostenart_id”] !=“1048”){
text = “varText2”;
}
break;

case “2” :
“varText2”;
break;
}

if (text == “varText1”) {
results.attr(“data-conditional”, “”);
results.show();
} else {
results.hide();
}

I would try << record.table[“tableName”].fields[“fieldName”] >>

That was an awfully quick answer! Thanks!

However, no luck. I changed the statement to:

if (record.table[“detail”].fields[“kostenart_id”] == “1048”) {
text = “varText1”;
}

And I get the error “Cannot read property “detail” from undefined”

I would need to take a look at the Connect document…is it something you are free to post out here?

If not, you can open an issue on our Website, the scrool down a little and you will see Report an issue.

Or you can open an issue by calling our tool free number: 1-866-348-5863.

In both case you need a valid OLCare license (for support).

How would I post it on the forum?

When you are typing text, reselect some text (any) then click on the icon that look like a chain pieces. On the target tab select same window(_self). On the third tab, select your Template and click the send to server.

The name of the field in your dialog box might differ from what I wrote before since mine is in french and I’m trying to translate.

Ok. Thanks! I made some progress but it does not appear to be quite right. On set seems to work but the other does not. All of the variable tables and text are at the bottom of the scripts pane.

http;//learn.objectiflune.com/qa/?qa=blob&qa_blobid=12794622475484384497

Thanks!

Did you include the row index for the detail table? Adding [0] after [“detail”] adds a reference to the first record in your ‘detail’ table

if (record.table[“detail”][0].fields[“kostenart_id”] == “1048”) {
text = “varText1”;
}

Thank You Erik!

The help from you and hamelj combined with my stubborn attitude resulted in success!

Here is the syntax that finally worked just in case it helps someone in a similar situation. Note that one of the keys was that ‘table’ had to be plural - record.tables

var text;
var itemCheck;

if (record.fields[“line_items”] == “1”) {
itemCheck = “1”;
} else{
itemCheck = “2”;
}

switch (itemCheck){
case “1” :
if (record.tables[“detail”][0].fields[“kostenart_id”] == “1048”) {
text = “varText1”;
}
else{
text = ‘varText2’;
}
break;

case “2” :
text = “varText2”;
break;
}

if (text == “varText1”) {
results.attr(“data-conditional”, “”);
results.show();
} else {
results.hide();
}