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

Javascript button Help - If userid != ownderid validation warning.
I want a validation on the Javascript buttin, where if the current user is not the owner of the record, then display an error message. Is this possible. It doesnt seem to like userid.
I have tried var currentUser = sforce.connection.getUserInfo().userId
$userid
etc.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var currentUser = sforce.connection.getUserInfo().userId
// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");
o.id = "{!ADR_Non_Approval_Object__c.Id}";
if(currentUser.id != o.OwnerId){
alert("You must be the Assigned Approver to Approve this request.");
}
else{
// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();
// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();
I have tried var currentUser = sforce.connection.getUserInfo().userId
$userid
etc.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var currentUser = sforce.connection.getUserInfo().userId
// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");
o.id = "{!ADR_Non_Approval_Object__c.Id}";
if(currentUser.id != o.OwnerId){
alert("You must be the Assigned Approver to Approve this request.");
}
else{
// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();
// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();
if(currentUser.id != o.OwnerId){
do you mean it should be
currentuser != o.ownerid
then display error message
else set value?
!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var currentUser = sforce.connection.getUserInfo().userId
// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");
o.id = "{!ADR_Non_Approval_Object__c.Id}";
if(currentUser!= o.ownerid ){
alert("You must be the Assigned Approver to Approve this request.");
}
else{
// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();
// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();
You initialised o in the line above but I can't see where its fields are initialised and the record saved, therefore o is still undefined.
if('{$User.Id}' != '{!ADR_Non_Approval_Object__c.OwnerId}'){
you have toi set the owner id before you comapre it.
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var currentUser = sforce.connection.getUserInfo().userId
// identify the record
var o = new sforce.SObject("ADR_Non_Approval_Object__c");
o.OwnerId = "{!ADR_Non_Approval_Object__c.OwnerId}";
o.id = "{!ADR_Non_Approval_Object__c.Id}";
if(currentUser.id != o.OwnerId){
alert("You must be the Assigned Approver to Approve this request.");
}
else{
// make the field change
o.Approval__c = "Approve";
o.Approval_Status_Date_Time__c = new Date();
// save the change
sforce.connection.update([o]);
}
//refresh the page
window.location.reload();
if('{$User.Id}' != '{!ADR_Non_Approval_Object__c.OwnerId}'){
if('{!CASESAFEID($User.Id)}' != '{!ADR_Non_Approval_Object__c.OwnerId}'){