How to think about "return result" correctly? How to return multiple results?

I recently learned how to use custom functions, and it’s really great, as they provide a lot of flexibility.

One limitation I encountered - and maybe I’m just conceptualizing it wrong - is that only a single result can be returned.

In the screenshot below of an On Change Event, listed at the top, we can see there is access to:

  • App Data
  • Page Data
  • Changed Value
  • Previous Value

If we want to change any properties in Page Data, this is a good place to be.

For comparison, let’s look at the inside of the custom function:

It takes the arguments inputText1 and inputText2.
(There doesn’t seem to be a limit on how many arguments we can add. So that’s good.)
But as for the result it will return, we are limited to only one.

Does this mean I should pack everything into a list when wanting to update multiple property values for the page? Then that list needs to be “unpacked” later in a place with a scope that gives access to Page Data.

In this example I kept everything very simple. But if an app has a page with many properties that need to be updated at once, having only one return value seems limiting to me. But maybe there is a way that programmers deal with this that I am not aware of… this limitation doesn’t seem unique to Backendless, but more of a programming convention sort of thing.

How do programmers work around this to update multiple property values within a single function?
Thanks.

Hi @Causality

you can pass your PageData or AppData or any data into the function and then modify it inside the function

Regards,
Vlad

1 Like

@vladimir-upirov
Thank youuuu!

I had to re-read your post a couple of times and try different things out for myself, but then it finally clicked.

I will post screen shots in case it helps others.
(Documenting the steps also helps solidify the concepts in my mind.)

We can create an argument for the specific purpose of passing Page Data into…
(In my test it is named pageData.)
And all of Page Data will flow through there!


Initializing the properties On Page Enter:


Something happens that modifies the properties. In my test it is an On Click Event.
The event calls a custom function (testIncrementFunc). That function gets access to Page Data.

page-data-properties-passed-into-custom-function


Once inside the function, we can use the Set Property In block as usual:


Above: Logic incrementing property values when a button is clicked.
propertyA = propertyA + 1
propertyB = propertyB + 2
propertyC = propertyC + 3


Result on page:

page-data-properties-update-function

It’s so simple now that I know this is possible!

Thank you so much! :v:

1 Like