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
KevinMcKevinMc 

Custom Formula based on Case Owner Role

I am trying to create a custom formula that takes the Case Owner Role and determines a geographical location of that Case Owner.   I've tried the following, but according to Salesforce Support, the $UserRole.Name is actually the current user, not the Case Owner.  Any help would be appreciated.
 
CASE ($UserRole.Name,"Product Support 1 (Denver)" ,"Denver",
"Product Support 2 (Denver)" ,"Denver",
"Ratings Product Support (Denver)" ,"Denver",
"Manager Client Services (Denver)" ,"Denver",
"Manager Product Support 1 (Denver)" ,"Denver",
"Manager Product Support 2 (Denver)" ,"Denver",
"Sales Inquiry (Denver)" ,"Denver",
"Manager Client Services - Europe" ,"London",
"Manager Product Support - Europe" ,"London",
"Product Support - Europe" ,"London",
"Support - Pacific" ,"Asia-Pacific",
"Support - Japan/Korea" ,"Asia-Pacific",
"Support - Asia" ,"Asia-Pacific","New York")
MyTwoCentsMyTwoCents
Here is a s-control using AJAX to save the record owner's role with the record. This computes everytime the page is viewed. Use this to get around the $UserRole.Name returning the role of the authenticated user. You can then use the new field in formulas, reports, views, mobile, etc.
 
This example is for the Account object.
1. Create an s-control of type "HTML" and add the code below.
2. Add a custom field "OwnerRole" to the Account object.
3. Add the s-control to the page layout of the Account object and set the width and height to 0
 
<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>
<script>
function loadRole() {
accountId = "{!Account.Id}";
ownerId = "{!Account.OwnerId}";
qOResult = sforce.connection.query("Select UserRoleId from User where id = '" + ownerId + "'");
records = qOResult.getArray("records");
for (var i=0; i<records.length; i++) {
var oEntry = records[i];
var roleId = oEntry.UserRoleId;
}
qRResult = sforce.connection.query("Select Name from UserRole where id = '" + roleId + "'");
records = qRResult.getArray("records");
for (var i=0; i<records.length; i++) {
var rEntry = records[i];
var name = rEntry.Name;
}
var acc = new sforce.SObject("Account");
acc.id = accountId;
acc.OwnerRole__c= name;
result = sforce.connection.update([acc]);
}
</script>
<body onload="loadRole()">
</body>
KevinMcKevinMc
Thanks... I'm going to give this a try.
RadagastRadagast

I can't get this to work unless the Account record is refreshed in the browser AFTER clicking on it, or the record is edited in some way. Otherwise, the OwnerId field remains empty.

Any ideas?