+ Start a Discussion
Glenn DalyGlenn Daly 

Adding clause criteria based on logged in user to custom button

I need to add an statement into this custom button so that it only runs if it meets a certain, how would I do this?
The statement essentially needs to say if the logged in user is equal to the R_D_Service_Owner__c or the project_owner__c then it can run, or if the logged in user profile equals 'system administrator' it can run, or if the logged in user equals a specific user id, or another specific user id it can run.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var r = new sforce.SObject("Product2");
r.id = "{!Product2.Id}";
r.Convert_to_Service_Catalogue__c = true;
result = sforce.connection.update([r]);

window.location.reload();

if ( result[0].getBoolean( "success" ) ) {

location.reload( true ); // refresh page

} else {

var errors = result[0].errors;

var errorMessages = "The Lifecycle Status must be Beta, and the following fields must be populated; Name, Unique ID, Jisc Directorate, Include in Dashboard, Service/Project Owner or else this record won't be converted to a Service Catalogue record";

for ( var i = 0; i < errors.length; i++ ) {
errorMessages += errors[i].message + '\n';
}

alert( errorMessages ); // display all validation errors

}
NagendraNagendra (Salesforce Developers) 
Hi Glenn,

Please find below link from stack exchange community where the similar post was addressed. Mark this as solved if it's resolved.

Best Regards,
Nagendra.P