'Make Conditional...' option not working

Hello, I’m putting together a letter template and I have a few element that I’m hiding or showing depending on variable data. I have some set to show only when data equals a certain value and some set to show when data begins with a certain character - however when I try to use the option to show when data ends with a certain character, the script is broken.

If I simply choose the option of setting the element as ‘Make Conditional…’ by right clicking on it and then telling it to Show - when the datafield - Ends with - the value, and press ‘OK’, the script comes up in the Scripts window with a small red ‘x’ by it and if I hover over it with my cursor it shows me a note saying “missing ) after condition”.

If I click into the script and expand it I can see that the default script is

if (record.fields[“datafield”].indexOf(“value”, 1 !== -1) {
results.show();
}else {
results.hide();
}

It shows an ‘x’ to the left of the first line, and underlines the open curly bracket at the end. I have tried putting a close bracket ‘)’ in various places near the end of this line but either it flags up a different kind of error in the script when I change it or on testing it my new form of the script doesn’t do what I wanted it to do (i.e. only show the element when the datafield on the record ends with that value).

Is there anyone with a better grasp of JavaScript than I (i.e. any grasp of it at all!) able to advise me how I could fix the script?

Thank you,

Lisa

There is indeed an issue with the expanded script for Ends With. We will make sure it is addressed in the oncoming release.

To fix the script you will need to add an extra right parenthesis at the end of the condition. See the sample below.

if (record.fields[“datafield”].indexOf(“value”, 1 !== -1)) {
results.show();
} else {
results.hide();
}

Hope this helps,

Erik

Thanks, Erik, unfortunately that was one of the modifications I tried before (and I’ve just tried it again just in case) and although it no longer indicates an error when the parenthesis has been added, when I put some test data through the condition does not work. The element will show whether the data ends with the value or not, even though the other conditional elements appear to be toggling visibility correctly.

Is there anything else I could try?

I would suggest using the following pattern:


var field = record.fields["datafield"];
var suffix = "value";
if (field.indexOf(suffix, field.length - suffix.length) != -1) {
    results.show();
} else {
    results.hide();
}

The oncoming release will not only have a fix for this bug, but it also has an updated script engine that allows you to do:

field.endsWith(suffix)

Are you on the preview tab?

I notice I need to be on preview tab to view conditions working or not.

That works! Thanks very much, Sander2.

Ricoh, yes, you can test if your conditions are working or not on the preview tab if your sample data contains the right set of values. I’ve been testing mine straight through the final Workflow process.