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
AAIAAI 

button with 3 conditions

Hi ,

I would need a button with 3 conditions. However, the phone condition doesn´t work. Any idea?. Thanks in advance
 
{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")}


var status = "{!Lead.Status}";
var Cartera__c = "{!Lead.Cartera__c}";
var Phone = "{!Lead.Phone}";
if (status == "Open" || status == "Assigned"){
if(Cartera__c!= null && Cartera__c!=""){
if(Phone != null && Phone !=""){
var lead = new sforce.SObject('Lead');
lead.id = "{!Lead.Id}";
lead.Status = "Pending conversion";
result = sforce.connection.update([lead]);
location.reload(true);
}
}else{
alert('Cartera Cannot be null');
}
}else{
alert("Invalid status. You can only submit to conversion the Lead if the status is Open or Assigned");
}
LBKLBK
This code seems to be working perfectly for me on a Javascript button.

I just replaced "{!Lead.Cartera__c}"; with "{!Lead.Email}"; because I dont have the custom field in my Lead object.

You don't have a else condition for the IF you have on Phone, is that what you have trouble with?

Here is the code that worked for me, if this helps you.
{!REQUIRESCRIPT("/soap/ajax/38.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/38.0/apex.js")}


var status = "{!Lead.Status}";
var Cartera__c = "{!Lead.Email}";
var Phone = "{!Lead.Phone}";
if (status == "Open - Not Contacted" || status == "Assigned"){
   if(Cartera__c!= null && Cartera__c!=""){
      if(Phone != null && Phone !=""){
         var lead = new sforce.SObject('Lead'); 
         lead.id = "{!Lead.Id}";
         lead.Status = "Pending conversion";
         result = sforce.connection.update([lead]);
         location.reload(true);
      }
   }else{
      alert('Cartera Cannot be null');
   }
}else{
   alert("Invalid status. You can only submit to conversion the Lead if the status is Open or Assigned");
}

It updated the data when I have Phone and email fields filled and Status =  "Open - Not Contacted"