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
sammy9099sammy9099 

Urgent: using Javascript custom button issue

Hi All , 

 

I have created a custom with javascript functionality and its working fine . I want when the same button is pressed twice or thrice  it should give alert message " Invalid action". I tried  using lot of things but its not working. I know it looks very easy but pls help me out in this issue. Below is the script:-

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

 

var leadstatus = '{!Lead.Status}';
if (leadstatus != "Z-Program Approved")
{
alert('An Elite Id cannot be assigned unless the Lead Status is equal Z-Program Approved');
}

else{

// Now calling the webservice to create a new Id 
var callback = "" + sforce.apex.execute("CreateliteId","createlite", {LeadId:"{!Lead.Id}"});

// If create and update was ok - just reload Lead page to see the id of the elite partner
if(callback == 'OK' ){

alert('The Elite Id has been assigned');
window.location.reload();
}

 

else{
alert('Error: ' + callback);
}}

sfdcfoxsfdcfox
Your web service method should simply provide an additional check to see if the data has already been created, and if so, return an error instead of "OK".
sammy9099sammy9099

Hey , 

 

Its not working with this solution also. is it possible for you to do some modifications in the above code ?

 

Regards

AnushaAnusha
Create a SysField(Checkbox) and in Script check for value of that field,

And in your WebSer

Example


{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}

//Query the SysField__c from Object and check bellow Condition and update this SysField in your WebService Method
if('{!Lead.SysField__c}'=='true'){
var leadstatus = '{!Lead.Status}';
if (leadstatus != "Z-Program Approved")
{
alert('An Elite Id cannot be assigned unless the Lead Status is equal Z-Program Approved');
}
else{
// Now calling the webservice to create a new Id
var callback = "" + sforce.apex.execute("CreateliteId","createlite", {LeadId:"{!Lead.Id}"});
// If create and update was ok - just reload Lead page to see the id of the elite partner
if(callback == 'OK' ){
alert('The Elite Id has been assigned');
window.location.reload();
}
}
}else{
alert(' Invalid action');
}
sammy9099sammy9099

Hi , 

 

when I execute the code with this method , All the time it is showing "Invalid action' . It is not executing the code in the IF condition. Any idea why this is happening ?

Regards

AnushaAnusha
Update that checkbox to false in final step of your method and update that to true in first step of web service method