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
Pamela DuPontPamela DuPont 

Custom Button Help Needed

Good morning,

I have a custom button that I can't seem to get to work. I'm very much a novice at writing code so I'm sure something is written incorrectly and I'm just not seeing it.

My custom button allows the user to submit the Case they created for review. However, they need to have a related Crop (custom related object) associated with that Case before it can be reviewed. There is a roll-up summary field on the Case called Crop_Record_Count__c that counts the number of Crop records associated. There needs to be at least 1 associated before the Case can be submitted for review.

Any ideas where I went wrong with the code?


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


/* Checks to make sure there is an associated Crop.
If TRUE, update the status and send for review.
If FALSE, provide an alert to fill add a Crop to the Case. */
function UpdateandValidate(){
var Crop = "{!Case.Crop_Record_Count__c}";
if(Crop != "0");
{
var objCase = new sforce.SObject('Case');
objCase.Id = '{!Case.Id}';
objCase.Review_Status__c = 'Submitted for Review by Rep';
var result = sforce.connection.update([objCase]);
alert('This case has been sent for review.');
document.location.href="/{!Case.Id}";
}
else {
msgAlert = "Please add a Crop before sending Case for review";
alert(msgAlert);
}
}


Thanks in advance!
Best Answer chosen by Pamela DuPont
Purushotham Reddy YellankiPurushotham Reddy Yellanki
Hi Pamela,

Try this code here, this should work

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

var Crop = "{!Case.Crop_Record_Count__c}";
if(Crop != 0){

//put your logic here
alert('Test Success');
window.location.reload();

}else{

alert('Please add a Crop before sending Case for review');
window.location.reload();

}




Thank you

All Answers

Purushotham Reddy YellankiPurushotham Reddy Yellanki
Hi Pamela,

Try this code here, this should work

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

var Crop = "{!Case.Crop_Record_Count__c}";
if(Crop != 0){

//put your logic here
alert('Test Success');
window.location.reload();

}else{

alert('Please add a Crop before sending Case for review');
window.location.reload();

}




Thank you
This was selected as the best answer
Pamela DuPontPamela DuPont
This worked perfectly! Thank you!