I have the below code for a JavaScript button which works fine
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
var entitlementQuery = "SELECT Application_Entitlement_ID__c FROM Account WHERE Id = '{!Opportunity.AccountId}' limit 1";
result = sforce.connection.query(entitlementQuery);
records = result.getArray("records");
var qr = sforce.connection.query("SELECT Id, Name FROM CaseTeamRole WHERE Name = 'Requestor'");
var crRecords = qr.getArray("records");
var rec = crRecords[0];
if(records[0]){
var relatedAccount = records[0];
try{
var recToCreate = new sforce.SObject("Case");
var recordTypeQuery = sforce.connection.query("SELECT Name,Id from RecordType WHERE developername = 'WE_Application'");
var recordTypeQueryResult = recordTypeQuery.getArray("records");
recToCreate.RecordTypeId = recordTypeQueryResult[0].Id;
var queueNameQuery = sforce.connection.query("SELECT Queue.DeveloperName, QueueId from QueueSobject WHERE Queue.DeveloperName = 'Wex_Europe_Applications'");
var queueNameQueryResult = queueNameQuery.getArray("records");
recToCreate.OwnerId = queueNameQueryResult[0].QueueId;
>>adding BusinessHours code here
recToCreate.AccountId = '{!Opportunity.AccountId}';
recToCreate.Subject = '{!Opportunity.Name}';
recToCreate.Origin = "Customer Application";
recToCreate.Opportunity__c = '{!Opportunity.Id}';
recToCreate.User__c = '{!Opportunity.OwnerId}';
recToCreate.EntitlementId = relatedAccount.Application_Entitlement_ID__c;
var result = sforce.connection.create([recToCreate]);
var ct = new sforce.SObject("CaseTeamMember");
ct.MemberId = "{!$User.Id}";
ct.parentId = result[0].id;
ct.TeamRoleID = rec.Id;
var result = sforce.connection.create([ct]);
// check that Case has been created
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " + result[0].errors.message);
}
}
catch(e){
alert("An Error has Occurred. Error: " + e);
}
}
I'm now trying to set the Business Hours for the Case, that's being created through the button and I've written
var businessHoursQuery = sforce.connection.query("SELECT Id FROM BusinessHours WHERE Name = 'Wex Europe CS Working Hours'");
var bhQueryResult = businessHoursQuery.getArray("records");
alert("bhQueryResult contains " + bhQueryResult);
recToCreate.BusinessHours = bhQueryResult;
My alert confirms that bhQueryResult
contains the 18 character BusinessHours Id but I then hit an error
Invalid Parameter Value
and I'm not sure why?
I do have read & edit access on the BusinessHours field, for the record's that're being created by the button.
var newId =bhQueryResult.substring(0,15);