I have a check in apex page with javascript code as below under script tags.

var proli ="{! $Profile.Name  }";
if(proli=='Abbott DM' || proli=='Field Profile' )
alert('{!$Profile.Name} not authorized to publish');
var isok =alert('{!$Profile.Name} not authorized to publish- Click OK to go back');
var a;
 a = setTimeout('window.location.href="/a4M?fcf=00BM0000000tpnc";',1);

I need the if clause above to check proli!='Abbott DM'. But it is not working. Can someone please let me know how to get that?

  • 1
    What you mean by not working? the value of proli depends on the time this snippet get executed
    – highfive
    Sep 14, 2015 at 12:08
  • when I place '!=' it's unable to validate and loading my page without the alert. And Settimeout not working Sep 14, 2015 at 12:09
  • does '!=' operator works here for 'if' clause? Sep 14, 2015 at 12:10
  • 1
    Seems it's quote marks. Can you go inside with alert(proli+'not authorized to publish'); ?
    – highfive
    Sep 14, 2015 at 12:15

1 Answer 1


Problem is not with the if condition but the way you pass values into the alert function. To evaluate {!$Profile.Name} it should be inside quote marks. So either you can use your proli variable to handle this

alert(proli + ' not authorized to publish');

Or you have to manage quote marks as below.

alert("'{!$Profile.Name}' not authorized to publish");

Apply this for the below lines of your snippet as well.

  • But it works fine for '==' condition fails for '!=' only Sep 14, 2015 at 13:02
  • When it's !=, it turns condition to false so the if block doesn't get hit isn't it? Try putting some alert() in the else block as well or check for any script errors with any inspect tool like firebug
    – highfive
    Sep 14, 2015 at 13:22

You must log in to answer this question.

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