BoxLang ArrayFind and ArrayContains

Not sure is bug or not but seems like is? I have following -

bx:script
variables.selectedProviderIDs = ;
for (row in prc.strAuth.rsSSOProviders) {
arrayAppend(variables.selectedProviderIDs, row.ssoProviderID);
}
</bx:script>
<bx:loop query=“prc.rsSSOProviders”>
bx:script
writeDump({
currentID: prc.rsSSOProviders.ssoProviderID,
selectedProviderIDs: variables.selectedProviderIDs,
selected: arrayContains(variables.selectedProviderIDs, prc.rsSSOProviders.ssoProviderID)
});
</bx:script> …

results as follows (switch to arrayFind returns all 0) -

It looks like the forum ate your code a bit - could you share a gist perhaps?

Main thing is if viewing the screenshot if we take the top struct item we have an array called selectedProviderIDs with integer values of 2,3, and 4. We also have an integer value (prc.rsSSOProviders.ssoProviderID) of 2. If I run arrayContains(selectedProviderIDs, prc.rsSSOProviders.ssoProviderID) I get false even though 2 should match the first value in the array. If I run arrayFind(selectedProviderIDs, prc.rsSSOProviders.ssoProviderID) I get 0

This is same thing in Lucee. You can see that values 2,3, and 4 are found. Value 1 is not, which is expected. -

Any chance you can make a small repro in try.boxlang.io? It’s just a bit hard to grok with everything else. :wink: And you said, it has the same issue in Lucee?

Not same issue in Lucee. Works in Lucee, no go in BoxLang

Gotcha - can you make a smaller repro in try.boxlang.io and then share the link?

This works here. Only difference is it’s a “fake” query and everything bx:script where as in actual app it’s bx:tag. I’ll see if I can do tag version in tryboxlang. Probably there’s a better way anyway but “ValueList” is not a valid function in Boxlang so I have kind of a verbose solution -

Doesn’t appear I can run tags in tryboxlang but two things: My actual code is pretty much identical to the tryboxlang code that works with the exception that it’s A) a query of a database and B) it’s mostly tag. Additionaly I haven’t tried ACF (I can though) but Lucee works fine as expected. I can make a test page that uses the exact same thing as tryboxlang code except tag and paste here if helps. Don’t think it’s going to run on tryboxlang though

Yeah I wouldn’t mind a file to run here. If the forum won’t let you attach it, email it to me at raymondcamden at gmail dot com.

just sent. Please let me know if doesn’t arrive. Thank you! I should have put br between the two sets but it’s 4 and then 4 of same thing done two ways, or so I think.

What the heck. So at the bottom of your script, I’m not seeing the dumps at all. I tried this:

<bx:loop query="qTAllProviders">
	DEBUG
	<bx:script>
		println('wtf');
		/*
        writeDump({
            currentID: qTAllProviders.providerID,
		    selectedProviderIDs: arrTSelectedP,
		    selected: arrayContains(arrTSelectedP, qTAllProviders.providerID)
        });
		*/
    </bx:script>
</bx:loop>

And I see 4 debugs, I see no wtf statements.

And it isn’t just the script. If I bx:dump variables, nothing is shown. But it’s running, cuz if I dump variables2, I get a proper error.

So yeah, if I switch to bx:output over the query, and don’t use writedump, but just:

	#arrayContains(arrTSelectedP, qTAllProviders.providerID)#

It seems to work right. I think there is an output bug here.

the version I’m running is - CF Engine: boxlang 1.0.0-snapshot

I just sent you a less verbose example that I think clearly shows the issue. Not sure where to go from here though.

Again though, I think it an output issue. I added:


	<bx:output>
	arrayContains(arrSelectedP, qAllProviders.providerID)=#arrayContains(arrSelectedP, qAllProviders.providerID)#
	</bx:output>

And it works. Something about bx loop over a query is suppressing output.

Can you confirm?

Ok, whew. I’m getting a bit tangled in my brain. I AM seeing output in both cases. I AM seeing selected have the right value.

The issue is that the text for the second H2, Loop via script, is shown at the END of the output.

So I believe it is just that - an output display bug. Can you test?

The issue is that in the first loop (by script) I get true then false which is correct. My array of providers in this case has a total of two values and one was selected. To determine whether “checked” should be set in the checkbox I compare the “selected” values against “all values”. In this case the user had previously selected provider #1 only so it shows as “true” (thus checked set for checkbox) whereas as provider #2 was not selected prior so shows false (not checked in checkbox). The 2nd loop should do the exact same thing except this time in tag loop but it does not. It returns false/false. That first item in the “loop by tag” should be true since the currentID is 1 and the “all providers” record ID is 1. The 2nd one should show false as before. The issue is they’re BOTH showing false which is incorrect.