Platform
Learn
Community
Support
Partner Center
Sign up
or
Log in
logout
Account Settings
Profile
messages
Messages
logout
Logout
Platform
Home
Downloads
IPP
Licensing
Project Sizing
Learn
Training
Documentation
Evaluation Guide
What's New
Community
Home
Forums
Forge
Ideas
Members
Support
Partner Guide
Resources Library
Opportunities
Account Management
Sign up
or
Log in
Home
Forums
Forge
Ideas
Members
Dear ,
What would improve your OutSystems Community experience? Let us know by taking this 2-minute survey.
Pick up the survey
Community
›
Forums
›
Technology & Integration
Selecting a query based on a variable
Community
›
Forums
›
Technology & Integration
Selecting a query based on a variable
New Post
New Post
Steve Dalgleish
Posted on 2014-04-09
Steve Dalgleish
Rank: #2862
Posted on 2014-04-09
Capture.JPG
So, I'm looking to create a flexible webblock where I pass in an input variable called ActivityView (text string). I want to use this variable to determine which database query is executed and returned to be bound to a TableRecords.
Now, using a switch in the preparation, I can determine which route the runtime follows and can input all the different queries. However, they must have different names, although I want to access it through the same name, ie bound to the TableRecords.
The query contains around 8-10 output structures but are broadly similar - looking at data using different filters.
Can anyone suggest an approach that might allow this?
Miguel Grilo
Posted on 2014-04-09
Miguel Grilo
Rank: #2380
Posted on 2014-04-09
Solution
Hi Steve,
you just have to assign to a local variable type record list and then make the TableRecords source this record list.
Best regards
Solution
Steve Dalgleish
Posted on 2014-04-10
Steve Dalgleish
Rank: #2862
Posted on 2014-04-10
Solution
Great, thanks Miguel, I wasn't aware I could create a record list variable with multiple structures - you learn something new every day.
Solution
João Fernandes
Posted on 2014-04-11
João Fernandes
Rank: #242
Posted on 2014-04-11
Solution
Just for reference, this is how you use a Screen Action to fetch data and display it in your screens:
Create a Screen Action;
Add input parameters (just like you create parameters in C# or Java methods);
Impleement the logic to fetch data
Add output parameters (instead of returning like in C# or Java you usually do, information gets in and out via input and output parameters)
Assign the output parameters with the data you've fetched
In the Preparation of your screen, invoke the User Action
In the Table Records (or List, Show, Edit Records), set its '
Source Record
' to the User Action output.
Check this reply to a similar question
. It contains some awesome screenshots.
The Pros
Basically all the benefits of encapsulation: you get to write the logic once and reuse it everyone.
You don't have to repeat yourself, and if you introduce a bug, it will be easier to find and fix.
The Cons
The OutSystems Platform does some awesome performance improvements. In particular, for Simple Queries the platform will only fetch the rows that you use on your logic or screens. Also, if you only display 50 records on your screen, the platform will only fetch 51 records, even if the actual query would return 2M records.
But... If you encapsulate a Simple Query inside an action, the Platform cannot easily infer where the query is being used, and is not able to make some performance improvements under the hood.
Solution
Jayson Leonor
Posted on 2014-04-11
Jayson Leonor
Rank: #6914
Posted on 2014-04-11
Solution
Hi Steve,
One problem you may face using an User Action as your datasource is that it cannot do query refresh when you have filters, pagination and sorting.
You may also want putting all your SELECT statements inside an Advanced Query, controlled by nested IF statements something like below:
IF (@table = 1)
BEGIN
SELECT field1, field2 FROM entity1
END
ELSE
BEGIN
IF (@table = 2)
BEGIN
SELECT field1, field2 FROM entity2
END
ELSE <and so on..>
END
You can just create an ActivityView output structure with all the common fields and ensure the fields in all your SELECT statements matches your output structure.
Cheers,
Jayson
Solution
Quick Reply
attachment
Choose File
No file chosen
Submit
Login to reply
New Post
Available Forums
Technology & Integration
News and Announcements
Forge Discussions
Meta
Community Quick Guides
Usability
Installation Troubleshooting
Personal Environment Troubleshooting
Forum Notifications
Email Digest Settings
Loading...