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
Chris WollastonChris Wollaston 

Button to Assign case to a user

Hi all,

I'm trying to create a button which will assign a case to a UserID which matches a custom field on the case. For example, our stores have an Account name of 'STORE NAME - xxxx' where xxxx is a four digital store number. In the account is a custom field 'Store Number'. In the case, we can the account of the store, but the User Name attached to the store is 'Store Manager xxxx' which matches the store number. Once all this is done, the page will refresh and show the Store Manager as the new case owner.

Is there any way in the Javascript below I can search for the relevant Store Manager user ID from the Store Number? My JS isn't that great.
Store ID is {!Case.StoreId__c}

-------------------------------------------------------------------------------
{!REQUIRESCRIPT("/support/console/41.0/integration.js")} 
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 

{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

{!REQUIRESCRIPT("/xdomain/xdomain.js")} 

var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 
caseObj.OwnerId = '{!$User.Id}'; 
var result = sforce.connection.update([caseObj]); 

if (result[0].success=='false') { 
alert(result[0].errors.message); 
} else { 
var refreshPrimaryTab = function showTabId(result) { 
var tabId = result.id; 
sforce.console.refreshPrimaryTabById(tabId, true); 
}; 

function doPrimaryTabRefresh() { 
sforce.console.getEnclosingPrimaryTabId(refreshPrimaryTab); 


doPrimaryTabRefresh(); 

}
----------------------------------------------------------------------

Shawn Reichner 29Shawn Reichner 29
My Java is not that great either at this point, but I would try to tackle this another way.  Can you create a Process in Process builder to fire a visual flow. In this visual flow, you can use the Case ID and Account Id to pass into the flow and then perform your search for the store manager where th store numbe rmatches in the flow and update the assignment of the case owner.   Before doing that though you will need to create a new custom checkbox field and edit your Java button code to check this new checkbox.  Then that is what will trigger your process to run and call the visual flow.  Hope that makes sense, but to sum it up what you would need to do is:

1. Create new custom checkbox field
2. Update Button to check this checkbox field on your case record
3. When checkbox is checked, the process you create in process builder will fire to call a visual flow
4. Create visual flow to use your Case ID and Account ID as parameters , and allow the flow to use that information to lookup the store manager and update the case owner field with the stor emanager ID. 

Hope this helps,

Shawn