Searching for a blank value

I am trying to create a database query function that enables and disables buttons and I’m not entirely sure where I’m going wrong. I have tried using the values of null, 0 and ’ ’ respectively in the line // if (item.corporateId === ’ ’ ) // and I’m not sure if I should rather use getItems or getTotalCount to fulfill this function instead.

function checkCorporateProfile() {
var user = wixUsers.currentUser;
wixData.query( “CorporateProfile” )
.eq( “corporateId” , user.id)
.find()
.then((result) => {
if (result.items.length > 0 ){
var item = result.items[ 0 ];
if (item.corporateId === ’ ’ ){
$w( “#btnCorpProf” ).disable();
$w( “#btnCorpProfile” ).disable();
$w( ‘#btnUpCorpProf’ ).enable();
} else {
$w( “#btnCorpProf” ).enable();
$w( “#btnCorpProfile” ).enable();
$w( ‘#btnUpCorpProf’ ).disable();
}
}
});
}

You can check for three possibilities:

if(item.corporateId === undefined ||
   item.corporateId === null ||
   item.corporateId === ''){

The value 0 is a number and is not relevant to a string.

Thank you, how would I go about defining “unidentified”? It is showing up as undefined.

@eringray1988 Sorry - I had a “be dumb” moment… undefined . I fixed it in my previous comment.

@yisrael-wix ah that’s all good, half my life is “be dumb” moments :sweat_smile: I have changed those fields now but it still doesn’t seem to be working. I must have done something else wrong. I’ll have to keep testing.

Hmm, I just looked a little more closely at your code and realized I missed something…

You are searching for records that have a certain corporateId . Then from the results you are checking if the the corporateId field is empty. Well, of course it won’t be empty if your search returned an entry.

If the idea is that you want to see if there any items (or not) that have a certain corporateId , then it’s really quite simple. In fact, you already did it by checking if result.items.length > 0 .

Howzbout we look at this a little differently and you just explain what exactly it is you’re trying to do.

Sorry I must have missed your reply notification. I’m back working on this feature again so I’d still love the help.

Basically what I’m trying to accomplish is that my users will create a personal user profile, from there they can upload a public corporate profile to a second database. If they haven’t uploaded one yet I need the buttons to view and update their profile to be disabled, but if they have uploaded one I need those buttons to become enabled and the button to upload the profile to be disabled so that they can only upload one profile per account.

@eringray1988 Well, you can query the database, and then enable/disable based on if any results were returned:

function checkCorporateProfile() {
   var user = wixUsers.currentUser;
   wixData.query("CorporateProfile")
      .eq("corporateId", user.id)
      .find()
      .then((result) => {
         if (result.items.length > 0) {
            $w("#btnCorpProf").enable();
            $w("#btnCorpProfile").enable();
            $w('#btnUpCorpProf').disable();
         } else {
            $w("#btnCorpProf").disable();
            $w("#btnCorpProfile").disable();
            $w('#btnUpCorpProf').enable();
         }
      });
}

Note: This code wasn’t tested, it’s to illustrate the idea. This should give you a good start.

@yisrael-wix thank you. I got it working, my issue was that I had incorrectly placed the enables and disables. Once I reverse them it worked like a charm.