1

In order to use the Service Console to display relevant details from Account/Contact/Asset while a Case is being created, I have a button on the Contact record that creates a 'shell' Case, saves it, which then creates the hooks necessary for the Case layouts' custom console components to display the related information.

I created console-specific layouts for two of our Contact recordtypes to include this button (as users outside the Console don't get any benefit from it), but I have found that certain Contacts result in a 'URL No Longer Exists' error rather than the desired new Case page, and yet the values referenced in the JavaScript are only the Contact.Id and the Contact.AccountId (both of which are populated on the aberrant Contact record(s)). (And apologies for the code formatting - my in-line comments are throwing wrenches.)

{!REQUIRESCRIPT("/support/console/33.0/integration.js")}

/* Require the AJAX Toolkit */
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}

/* Verify sforce.console now exists */
console.log("sforce: %o", sforce);

/* Get the enclosing tab's ID, so that openSubtab()
can be called with the correct parameter*/
sforce.console.getEnclosingPrimaryTabId(function(response) {

/* Remember the primary tab ID for openSubtab() */
var primaryTabId = response.id;
console.log("primaryTabId: %o", primaryTabId);

/* Create Case using AJAX toolkit */
var cs = new sforce.SObject("Case");
cs.RecordTypeId = "01233000000MHqy"; /* Console Shell */
cs.Subject = "Subject required";
cs.Case_Issue__c = "** Please Select Case Issue **";
cs.ContactId = "{!Contact.Id}";
cs.AccountId = "{!Contact.Account_ID__c}";
cs.Status = "Open";

/* Create the Case */
var result = sforce.connection.create([cs]);
cs.Id = result[0].id;
if(result[0].getBoolean("success")) {
console.log("new case created with id " + result[0].id);
} else {
console.log("failed to create case " + result[0]);
}

/* Define the target URL using a dummy Case ID */
var url = "{!URLFOR($Action.Case.View, '500')}";

/* Replace the dummy Id with the actual Case.Id */
url = url.replace("500", cs.Id);

/* Define other parameters for openSubtab() */
var isActive = true;
var tabLabel = null;
var subtabId = null;

/* Call openSubtab() */
sforce.console.openSubtab(
primaryTabId, url, isActive, tabLabel, subtabId);
});

Again, most of the Contacts with this recordtype where this button produce the expected result, a new Case record; others result in the 'URL No Longer Exists' error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.