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!');
    }
3
  • I don't see any issue with your code.
    – Reshma
    Nov 24, 2016 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. Nov 24, 2016 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, 2016 at 7:16

1 Answer 1

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!');
}
2
  • Thanks!! Don't know why it takes check as string. Nov 24, 2016 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, 2016 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .