You need to sign in to do that
Don't have an account?

custom Button executing javascript not deleting records
Hey Guys,
I am trying to create a custom button executing javascript. This button is same like DELETE button . it will also delete records only when certain checkbox is NOT checked off. If that checkbox is checked off , it should not delete records rather it should give an alert message. Below is the javascript. But Everytime , I click the button on record , I get this error: Please help me in fixing the code.
A problem with the OnClick JavaScript for this button or link was encountered:
Unexpected token '{'
Javascript:
{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
var oppty = new sforce.SObject('OpportunityLineItem');
oppty.Id = '{!OpportunityLineItem.Id}';
If ( oppty.Trafficked__c = 'False'){
var resultoppty = sforce.connection.delete([oppty]);
}
else
{
alert('cannot delete.please retry again');
location.reload();
}
If ( oppty.Trafficked__c = 'False'){
replace with
If ( oppty.Trafficked__c == 'False'){
Or just
If ( ! oppty.Trafficked__c){
Hi,
Thanks for responding. I did use that but still the same error.
Regards
There deleteIds and not delete. Replace delete with deleteIds in sforce.connection.delete
Again the same error.
Remove the capital I from the if, thats what causing the unexpected token error.
As DeepaAnika.Ankali said, use deleteIds not delete.
Fixed code :
{!REQUIRESCRIPT('/soap/ajax/28.0/connection.js')}
if (!{!OpportunityLineItem.Trafficked__c}){
var resultoppty = sforce.connection.deleteIds(['{!OpportunityLineItem.Id}']);
location.reload();
}
else
{
alert('cannot delete.please retry again');
location.reload();
}
Dont forget to mark as solved if it fix your issue!
It's again the same error
A problem with the OnClick JavaScript for this button or link was encountered:
Unexpected token '{'