Hide Server Connect data results based on another SC result

Hello,

How do I go about hiding dynamic results from a server connect query using App Connect.

Example:
I want to get all possible products that my customer can order and then I want another server connect to get all the products that my customer has already ordered. Then App Connect should hide the products that are already ordered and only show me the products that have not been ordered.

I would go like this, assuming that the orders table has a subtable with its order-products:

-get parameter to filter the client : $_GET.client_id

-DB Schemas (basic columns)
products
prd_id
prd_Name

clients
cln_id
cln_Name

orders
ord_id
ord_Cln_id
>order_products
ord_prd_id

Serverconnect:

  • Add a query step fetching products and enable DISTINCT
  • then Left Join the order-products (prd_id == ord_prd_id)
  • then Join the orders
  • Add a Filter/Condition (ord_Cln_id != $_GET.client_id)
  • And Select ord_prd_id (and any other column you want)

This will list all the products that the $_GET.client_id hasn't ordered...

Just the ifrst thoughts... I don't go deep in details
Wappler gives you the right to go as far as you want.

If you need help on something mentioned above please drop it here
:slightly_smiling_face:

You can do this server side with a single server action and 2 database queries.

You can filter a query based on the user id and return the users products. In another query, just after this one you can filter the products and exclude the ids of the products returned from the users products query using NOT IN.

Sorry, I forgot to mention that the data will be from an API, hence why there are 2 Server Connects getting this data.

The only way for me to remove the products would be with App Connect I believe.

Then I suppose you could use Array List for that and:

  • create an ArrayList id=newProducts...
    (Define the schema like the products schema)
  • Then add a new/extra field prd_Sold(boolean) on the newProduct ArrayList (you see why at the next step)
  • Create a repeat on the one products API and compare to the orders(products ordered from client).
  • Add a condition step and if the product_id exists in the orders api then set the prd_Sold(boolean)==true otherwise false.

This way, you have a query with all the produts and on your page you can filter by prd_Sold==false to show only the products that have not been ordered by the client

Something like that...

*More about Array Lists in this great tutorial from Hyberbytes:

I have everything setup and while it seems like it's going to work, I can't figure out how to do the compare between both datasets?

Sorry my friend but I can't understand...

  1. You have it working already?
  1. Add a repeat step based on the one API and inside it search for the current primary key on the other API...

Sorry I can't talk in specific because I don't know the exact layout/results of your API

The array is set up and should work.

However I have no idea how to do the search/compare between the 2 datasets. Both datasets have a code column which is the id of the product that should be used to compare.

Please share a screenshpt of the 2 api results (just 1 record so i see the fields/columns you have)

image

I am comparing the "region_id" and the "code" in the 2 datasets.
What I'm trying to achieve is if the "region_id" is included in the first dataset, then in the 2nd dataset that same "code" should show as false in the activated field.

Repeat on activations:
-if regions.values('code').contains(region_id)

  • then
    activated.setValue(false)
  • else
    activated.setValue(true)

You loop on all the activities records and each time you check if the regions (array of the 'code' values) contains the current 'region_id'

Got it?

@famousmag Everything is working right now. I've gotten the condition to work and show false or true.

But the only issue I have now is that because there a 2 arrays which are being compared, Wappler keeps pulling in and comparing only the first data array. How do I get Wappler to run through the whole entire array data?

image
image

where are you clicking to bind the region_id?
image

Anyway just delete the activations[0] in the front and leave only region_id inside the parenthesis

image

I'm choosing the "region_id" value from the activations array
The "activations" and "regions" array's are 2 separate array's.

wait...

Is'n that the result of your APIs?
image

It is the 2 arrays that are already taken the values from the 2 APIs?
You have already assign the values of each API in a different Array List witrh an ADD ALL TO Array LIST step?

Anyway, you should click on the region_id you see inside the activations repeat
Can you share a screenshot of your serveraction so I can understand what you have so far?

You have:

  • activationAPI
  • regionsAPI
  1. Then add a create ArrayList (id=productsArrayList) and give it a scema you want
  2. Then you add a repeat on activationAPI
    add inside it:
  • add to productsArrayList all the values you want (the schema you created on step 1)
  • add the activated setValue based on the condition above

That is the basic idea

I keep playing around with this and it just got even more confusing.

Are you able to show me an example of the Server Connect on how to achieve this?

Don't play around my friend...
You just have to understand
a)what you have
b)what you need
then the only thing missing is the HOW to arcieve what you need

Just pay attention to this general steps guide:

You have 2 external APIs (they output a query).

Then we add one Array List to hold all the products
give it the schema you want for example:

  • prod_id
  • Prod_Name
  • prod_Code
  • whichever else column you want and
  • prod_activated (will hold if the product will be listed or no)

Then add a repeat step based on the activationsAPI.
inside the repeat:

  • add to the ArrayList columns the product details you want
  • add a condition and check if the regionsAPI.values('code').contains(region_id)
    the region_id you bind it form inside the repeat's content
    -if the condition is true (the client has already ordered that product)
  • you set the ArrayList's prod_activated field equal to true
    Otherwise
  • you set the ArrayList's prod_activated field equal to false
  • After the Repeat you get the ArrayList value and check the output so you can see it in your page

Now in your page,

  1. add a Serverconnect component, based on the above serveraction.
  2. add a DataView component and
    a) set its DataSource to the above arrayList Serveconnect.ArrayListProducts
    Up to now the DataView contains all the products
    b) if you want to filter them you can set the DataView's filter to prod_activated==true

I hope you understand it...
Start with this guide and if you have problem share a screenshot in order to help you

So I tired all of that and It's not coming out exactly how I provisioned it.


image

I believe I'm messing up around these steps. Also should the repeat be a list of all the products and not the activations? And then the condition would check if the product is included in the activation?

Usually I'm really good a Wappler but this is so confusing for me today, and I know I'll have to use this type of query a lot this week.