Looking for a piece of code

I have a database called “Members”. This database have fields called “Email, FirstName,Lastname,Type” It is a database of User.

On click of a button, I am looking for a peace of code that would look for the currentUser line in my database, look in the field TYPE and do a IF ELSE that would tell, IF field “Type” = “blue” open page /bluepage ELSE open page /yellowpage

Can someone help me on this little peace of code :slight_smile:

thanks

Hi,

Some general code, hope you’ll be able to adapt it to your site:

import wixUsers from 'wix-users';
export function button1_click(){
    const currentUser = wixUsers.currentUser;
    if (currentUser.loggedIn) {
        currentUser.getEmail().then(email => {
            wixData.query('collectionName').eq('email', email).find().
                then(result => {
                    if (result.items.length > 0){
                        //item found in database
                        const itemInData = result.items[0];
                        if (itemInData.Type === 'blue'){
                            //do something for blue
                        } else {
                            //do something else
                        }
                    }
                })
        });
    }
}

Liran.

This is great…it’s working…thanks :slight_smile:

Can you provide the code to compare from two drop down items,

Suppose A is selected from drop down and B is selected from another drop down and comparison A vs B page is present on another page . so when user click on to the button after selecting the from both the drop down relevant result page should open.

thanks in advance