function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KR_ForceKR_Force 

|| 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.");
}
}
Best Answer chosen by KR_Force
CheyneCheyne
I think you need to use an AND condition. This condition

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

CheyneCheyne
I think you need to use an AND condition. This condition

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.
This was selected as the best answer
KR_ForceKR_Force
Thank you Cheyne....that worked. 
CheyneCheyne
No problem, glad I could help! Feel free to mark it as solved so that others can benefit.