I have a Javascript button on Case that merely changes the owner when clicked, so far so good. But I'd like to extend it with a tiny bit of validation that chck to see whether there's a picklist value that is empty (that is, not set) on the Case. If so, it throws an alert, else updates the case with the new ownerId. Here's what I've got:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
var updateRecord = new Array();
var myquery = "SELECT Id,txFaultRequestInfo__c,pl_ReasonForAssignment__c FROM Case WHERE Id = '{!Case.Id}' limit 1";
result = sforce.connection.query(myquery);
records = result.getArray("records");
if(records[0])
{
var update_Case = records[0];
if("{update_Case.pl_ReasonForAssignment__c}" == '')
{
alert("Picklist value is not set!");
}
else
{
update_Case.OwnerId = "00G20000000jeqC" ; /* New Value */
//update_Case.OwnerId = "00G20000000jdLD"; /* Older Value */
updateRecord.push(update_Case);
}
}
result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;
No matter what, it always evaluates the if condition as false and goes to the else condition that updates the OwnerId. Can you spot the error?
"{update_Case
should be this"{!update_Case
. But if that field is editable in the page, then perhaps you should be looking at the input field value not the value when the page was rendered.