0

I have below code where if statement that needs to work based on 'check' boolean value, is not working properly.

Although, 'check' value is true it navigates to the else block. Can someone please let me know why this is happening?

Code

    {!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
    var user = sforce.connection.getUserInfo();
    var check=false;
    check=sforce.apex.execute("CheckAOCAccess","AOCAccess",{LoggedUser:"{!User.Id}"});
    alert('check@'+check);
    var vUrl = '/apex/ABV_AoCSignatureCapturOnline?actId={!Account.Id}';
    if(check==true){ // This line fails to work based on check value
        alert('check@1'+check); window.open(vUrl);
    } 
    else {//Everytime else block is fired
         alert('check@2'+check);
         alert('You are have not the privilege for Acknowledgement of Contents!');
    }
  • I don't see any issue with your code. – Reshma Nov 24 '16 at 7:08
  • In case where check value is true, it should only execute window.open(vUrl) and stop. But it goes to else block. That's the problem. – Testing_SFDC Nov 24 '16 at 7:13
  • can you please add console.log for sforce.apex.execute("CheckAOCAccess","AOCAccess",{LoggedUser:"{!User.Id}"}); and check what exactly the value is returned. – RCS Nov 24 '16 at 7:16
2

Can you please try below code, if the check value is coming as true from check=sforce.apex.execute("CheckAOCAccess","AOCAccess",{LoggedUser:"{!User.Id}"});

if(check=='true'){ // This line fails to work based on check value
    alert('check@1'+check); window.open(vUrl);
} 
else {//Everytime else block is fired
     alert('You are have not the privilege for Acknowledgement of Contents!');
}
  • Thanks!! Don't know why it takes check as string. – Testing_SFDC Nov 24 '16 at 7:21
  • 1
    @SFDC_Learner It's an artifact of how it works; it's actually a SOAP call, so the type gets a bit mangled. – sfdcfox Nov 24 '16 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.