Change button destination based on database value

Hi All,

I’m trying to create a site with 3 different profile types (Charity, Agency & Freelance). I’ve created the 3 read-only public profiles on their own dynamic URLs and 3 read-write edit profiles also on their own dynamic URLs.

At the moment there are no errors when writing the code but clicking on the button on the site (when viewing the published version) doesn’t actually do anything…

Code is below and any pointers would be greatly appreciated!

import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data';

export function editProf_click(event) {

let user = wixUsers.currentUser;
user.getEmail()
  .then( (email) => {      
wixData.query('Members')
   .gt("Email Address", email)
   .find()
   .then( (results) => {
 if(results.items.length > 0) {
 let organisationType = results.query;
 
 if(organisationType === "charity") {
               wixLocation.to('members/edit/charity');
           }
 else if(organisationType === "freelance"){
               wixLocation.to('members/edit/freelance');
           }
 else {
                wixLocation.to('members/edit/agency');
           }
       }

 else{
       }
   } );
});
}

As an aside - this is actually only taking users to the static version (which should present a 404), ideally I’d be sending them to their dynamic URL which is stored in the database however the auto-generated Field Keys are “link-members-title”, “link-members-title-1” etc and I’m facing a parsing error due to the “-” icons. I tried unicode escaping but it’s not recognising them. Bonus points for any help there too!

Thanks in advance :slight_smile:

It seems you’re missing a slash / at the beginning of the destination string.
Also make sure the organisationType is store in the “query” field (if it’s stored in another field change your code in accordance).

Thanks so much J.D. - solved. :slight_smile: Have a good one!

You’re welcome :slight_smile: