Trying to Return a Single Value From an Array Gives An Error

Wappler 2.9.1

Steps to create:

  1. Create a multi-page query, e.g. called lookups which returns a couple of columns such as id and lookup_function from a database table.
  2. The goal is to obtain the value of id when, for example, lookup_function == "stripe_fee_category", and assign it to a session variable.
  3. The assignment that should work is:
{{lookups.where(lookups.lookup_function, "==", "stripe_fee_category").top(1).id}}
or
{{lookups.where(lookups.lookup_function, "==", "stripe_fee_category")[0].id}}
  1. When you run either of these server actions, Wappler gives the following error:
{code: 0, file: "C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php",…}
code: 0
file: "C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php"
line: 35
message: "Undefined index: "
trace: "#0 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php(35): exception_error_handler(8, 'Undefined index...', 'C:\\Users\\anton\\...', 35, Array)↵#1 [internal function]: lib\core\formatter_where(Array, NULL, '==', 'stripe_fee_cate...')↵#2 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(396): call_user_func_array('\\lib\\core\\forma...', Array)↵#3 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(354): lib\core\Parser->objectMember(Object(Closure))↵#4 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(296): lib\core\Parser->primary()↵#5 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(273): lib\core\Parser->group()↵#6 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(253): lib\core\Parser->unary()↵#7 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(243): lib\core\Parser->multiplicative()↵#8 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(233): lib\core\Parser->addictive()↵#9 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(223): lib\core\Parser->bitwiseShift()↵#10 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(213): lib\core\Parser->relational()↵#11 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(203): lib\core\Parser->equality()↵#12 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(193): lib\core\Parser->bitwiseAnd()↵#13 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(183): lib\core\Parser->bitwiseXor()↵#14 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(173): lib\core\Parser->bitwiseOr()↵#15 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(161): lib\core\Parser->logicalAnd()↵#16 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(145): lib\core\Parser->logicalOr()↵#17 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(141): lib\core\Parser->conditional()↵#18 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(86): lib\core\Parser->expression()↵#19 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(221): lib\core\Parser->parse('lookups.where(l...', NULL)↵#20 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\modules\core.php(109): lib\App->parseObject('{{lookups.where...')↵#21 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(173): modules\core->setsession(Object(stdClass), 's_expense_strip...')↵#22 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(137): lib\App->execSteps(Object(stdClass))↵#23 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(107): lib\App->execSteps(Array)↵#24 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(72): lib\App->exec(Object(stdClass))↵#25 C:\Users\anton\Dropbox\workshop-angel\dmxConnect\api\subscriber_user_settings\set_session_variables.php(8): lib\App->define(Object(stdClass))↵#26 {main}"

Antony why you keep posting the same topics over and over again?
Your other topic with all the comments there is more than enough.

You can just post the result of:

lookups.where(lookups.lookup_function, "==", "stripe_fee_category")[0]

or

{{lookups.where(lookups.lookup_function, "==", "stripe_fee_category").top(1)}}

so we can see what your data is exactly…

And please stop posting the the same issue in multiple topics. It doesn’t help.

Because it is clear to me it is a bug, so I have posted it as a bug rather than something 28 posts down what became a very long discussion!

1 Like

For clarity! :slight_smile:

Antony, one topic is enough.
Posting the same thing over and over again makes it harder for us to follow.
It’s us who check if it’s a bug or not.
Keep posting in the same topics in the future. You are not really helping doing this, really :slight_smile:

1 Like

Would you mind answering my question:

the result of:

{{lookups.where(lookups.lookup_function, "==", "stripe_fee_category")[0]}}

or

{{lookups.where(lookups.lookup_function, "==", "stripe_fee_category").top(1)}}

?

@teodor, can you tell me how to show you that?

Well add some setValue step with any of these expressions, enable output and just copy the response from your server action in the browser dev tools.

With this statement in my server action:

eight

I get the following error message as the server action loads:

{code: 0, file: "C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php",…}
code: 0
file: "C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php"
line: 35
message: "Undefined index: "
trace: "#0 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\formatters\collections.php(35): exception_error_handler(8, 'Undefined index...', 'C:\\Users\\anton\\...', 35, Array)↵#1 [internal function]: lib\core\formatter_where(Array, NULL, '==', 'stripe_fee_cate...')↵#2 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(396): call_user_func_array('\\lib\\core\\forma...', Array)↵#3 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(354): lib\core\Parser->objectMember(Object(Closure))↵#4 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(296): lib\core\Parser->primary()↵#5 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(273): lib\core\Parser->group()↵#6 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(253): lib\core\Parser->unary()↵#7 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(243): lib\core\Parser->multiplicative()↵#8 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(233): lib\core\Parser->addictive()↵#9 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(223): lib\core\Parser->bitwiseShift()↵#10 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(213): lib\core\Parser->relational()↵#11 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(203): lib\core\Parser->equality()↵#12 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(193): lib\core\Parser->bitwiseAnd()↵#13 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(183): lib\core\Parser->bitwiseXor()↵#14 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(173): lib\core\Parser->bitwiseOr()↵#15 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(161): lib\core\Parser->logicalAnd()↵#16 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(145): lib\core\Parser->logicalOr()↵#17 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(141): lib\core\Parser->conditional()↵#18 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\core\Parser.php(86): lib\core\Parser->expression()↵#19 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(221): lib\core\Parser->parse('lookups.where(l...', NULL)↵#20 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(206): lib\App->parseObject('{{lookups.where...', NULL)↵#21 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\modules\core.php(99): lib\App->parseObject(Object(stdClass))↵#22 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(173): modules\core->setvalue(Object(stdClass), 'test1')↵#23 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(137): lib\App->execSteps(Object(stdClass))↵#24 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(107): lib\App->execSteps(Array)↵#25 C:\Users\anton\Dropbox\workshop-angel\dmxConnectLib\lib\App.php(72): lib\App->exec(Object(stdClass))↵#26 C:\Users\anton\Dropbox\workshop-angel\dmxConnect\api\subscriber_user_settings\set_session_variables.php(8): lib\App->define(Object(stdClass))↵#27 {main}"

And what without the [0] at the end?

I get the same error.

Well then something is totally wrong…
Are you sure {{lookups}} returns anything at all?

So that’s the problem. You asked for a solution to something that was already broken ergo everything else was bound to be broken :wink:

Antony, there is an important lesson to learn here. People don’t ask for more information about your problem just because. They do it based on solid grounds.

Instead of coming with the data structure you are querying and what you need to achieve you came with this works because I say so so how can I do this other thing?

The problem is that the part you assumed was working isn’t.

five

I can only see this when I disable the Set Value step and just have the Database Query on its own… The Set Value continues to give the error message last shown.

I’ve also tried deleting the Database Query and re-making it, as that can sometimes fix things, but it hasn’t in this case.

Which is why when realising this I submitted a bug report!

That’s not really the reply of the server action.
Run your page and look in the browser dev tools - network - xhr.
I need to see the output there.

I will leave it rest here…

1 Like

But Teodor, what I showed you is the text from there!

Antony …
I need to see what your server action returns before you try to use all these setValue or setsession or whatever set steps you are using with some formatters applied to them!

The dmx.app.data screenshot shows me nothing of this.

So with just the Database Query of the table lookups?