You need to sign in to do that
Don't have an account?
Evan C. Decker
Help with making fields required in javascript button
Hello, we have the following button that creates a new case record automatically, the problem is this doesn't take into account required fields on the case and completely bypasses the requirement:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} // Save url var url = parent.location.href; var bug = new sforce.SObject('Case'); bug.RecordTypeId='012U0000000Qqxb'; bug.ParentId='{!Case.Id}'; bug.Service_Product__c='{!Case.Service_Product__c}'; bug.Product_Version__c='{!Case.Product_Version__c}'; bug.OwnerId='00GU0000001gEO8'; bug.SR__c='{!Case.SR__c}'; bug.ES__c='{!Case.ES__c}'; bug.Subject='{!Case.Service_Product__c}'+ ' ' + '{!Case.Product_Version__c}' + ' - ' +'Doc Defect' var result = sforce.connection.create([bug]); // Process result, if success refresh page if( result[0].getBoolean("success") ){ window.location.href = 'https://calabrio.my.salesforce.com'+'/' + result[0].id; } else { log("Failed to update project: " + result[0]); }Based on other questions asked in the community, I've come up with the following, adding the required fields into if statements, but it still doesn't work:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} /*Required fields*/ var DocTitle = '{!Case.Book_Title__c}'; var SectionTitle = '{!Case.Section_Title__c}'; var Description = '{!Case.Description}'; /*Field requirements*/ if(DocTitle == ''){ alert('The Doc Title field is required.') } ifSectionTitle == ''){ alert('The Section Title field is required.'); } if(Description == ''){ alert('The Description field is required.') } /*Once required fields are filled in*/ else{ // Save url var url = parent.location.href; var bug = new sforce.SObject('Case'); bug.RecordTypeId='012U0000000Qqxb'; bug.ParentId='{!Case.Id}'; bug.Service_Product__c='{!Case.Service_Product__c}'; bug.Product_Version__c='{!Case.Product_Version__c}'; bug.OwnerId='00GU0000001gEO8'; bug.SR__c='{!Case.SR__c}'; bug.ES__c='{!Case.ES__c}'; bug.Subject='{!Case.Service_Product__c}'+ ' ' + '{!Case.Product_Version__c}' + ' - ' +'Doc Defect' var result = sforce.connection.create([bug]); // Process result, if success refresh page if( result[0].getBoolean("success") ){ window.location.href = 'https://calabrio.my.salesforce.com'+'/' + result[0].id; } else { log("Failed to update project: " + result[0]); } }
I receive the error "A problem with the OnClick JavaScript for this button or link was encountered: Unexpected token )" Any ideas? Thanks in advance!