• Purushotham Reddy Yellanki
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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!
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!