You need to sign in to do that
Don't have an account?

|| OR condition is not working in oneClick javascript button.
Can anyone please look into this and help to find the error? code works perfectly fine when i validate only one profile ID in the 'IF' condition when add other 2 profile ID's its not respecting the conditions and leting all actions entering to into the IF.
{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
var sr = new sforce.SObject("Contract");
sr.Status = "{!Contract.Status}";
var initial = sr.Status;
if ( '{!$User.ProfileId}'!='00e30000000bqt9'|| '{!$User.ProfileId}' !='00e80000001BvTe'||'{!$User.ProfileId}' != '00eA0000000MKTH')
{
alert('{!$User.ProfileId}');
alert('You are not authorized to cancel the agreement ...........');
window.parent.location.href=window.parent.location.href;
}
else
{
if(initial=='Draft'||initial=='Executed')
{
var sr = new sforce.SObject("Contract");
sr.id = "{!Contract.Id}";
sr.Status = 'Cancelled';
result = sforce.connection.update([sr]);
window.location.reload();
}
else
{
alert("You cannot cancel expired agreements.");
}
}
{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
var sr = new sforce.SObject("Contract");
sr.Status = "{!Contract.Status}";
var initial = sr.Status;
if ( '{!$User.ProfileId}'!='00e30000000bqt9'|| '{!$User.ProfileId}' !='00e80000001BvTe'||'{!$User.ProfileId}' != '00eA0000000MKTH')
{
alert('{!$User.ProfileId}');
alert('You are not authorized to cancel the agreement ...........');
window.parent.location.href=window.parent.location.href;
}
else
{
if(initial=='Draft'||initial=='Executed')
{
var sr = new sforce.SObject("Contract");
sr.id = "{!Contract.Id}";
sr.Status = 'Cancelled';
result = sforce.connection.update([sr]);
window.location.reload();
}
else
{
alert("You cannot cancel expired agreements.");
}
}
if ( '{!$User.ProfileId}'!='00e30000000bqt9'|| '{!$User.ProfileId}' !='00e80000001BvTe'||'{!$User.ProfileId}' != '00eA0000000MKTH')
will be true if the user profile ID is not equal to one of those profile IDs, which is always true -- if the ID is 00e30000000bqt9, then it is not equal to 00e80000001BvTe. If you use
if ( '{!$User.ProfileId}'!='00e30000000bqt9' && '{!$User.ProfileId}' !='00e80000001BvTe' && '{!$User.ProfileId}' != '00eA0000000MKTH')
then the condition will be true if the user profile ID is not equal to any one of them, so only user with one of those three user profile IDs will be authorized.
All Answers
if ( '{!$User.ProfileId}'!='00e30000000bqt9'|| '{!$User.ProfileId}' !='00e80000001BvTe'||'{!$User.ProfileId}' != '00eA0000000MKTH')
will be true if the user profile ID is not equal to one of those profile IDs, which is always true -- if the ID is 00e30000000bqt9, then it is not equal to 00e80000001BvTe. If you use
if ( '{!$User.ProfileId}'!='00e30000000bqt9' && '{!$User.ProfileId}' !='00e80000001BvTe' && '{!$User.ProfileId}' != '00eA0000000MKTH')
then the condition will be true if the user profile ID is not equal to any one of them, so only user with one of those three user profile IDs will be authorized.