We help IT Professionals succeed at work.
Get Started

number outside valid range

-Dman100-
-Dman100- asked
on
1,704 Views
Last Modified: 2012-05-11
I am using the following javascript code to insert a new lead record (see code below).  I'm getting the following error for some records that do not have a net patient revenue field:

{errors:{fields:'Net_Patient_Revenue__c', message:'Net Patient Revenue: value outside of valid range on numeric field: NaN', statusCode:'NUMBER_OUTSIDE_VALID_RANGE',},id:null,success:false',}

I've tried multiple ways to overcome this error.  When the net patient revenue record does not exist, I just want to assign the value as zero.

Thanks for any help.
{!requireScript("/soap/ajax/11.1/connection.js")} 

var netPatientRev; 
if ("{!Account.NetPatientRevenue__c}" != null) { 
netPatientRev = "{!Account.NetPatientRevenue__c}"; 
} 
netPatientRev = netPatientRev.replace("$", ""); 
netPatientRev = netPatientRev.replace(/,/g, ""); 
netPatientRev = parseFloat(netPatientRev); 

var lead = new sforce.SObject("Lead"); 
var answer1 = prompt ("What is First Name?"," "); 
var answer2 = prompt ("What is Last Name?"," "); 
lead.Company = "{!Account.Name}"; 
lead.Account__c = "{!Account.Id}"; 
lead.Street = "{!Account.ShippingStreet}"; 
lead.City = "{!Account.ShippingCity}"; 
lead.State = "{!Account.ShippingState}"; 
lead.PostalCode = "{!Account.ShippingPostalCode}"; 
lead.Country = "{!Account.ShippingCountry}"; 
lead.Net_Patient_Revenue__c = netPatientRev; 
lead.Phone = "{!Account.Phone}"; 
lead.Med_Surg_Beds__c = "{!Account.Bed_Size__c}"; 
lead.Website = "{!Account.Website}"; 
lead.Firstname = answer1 
lead.LastName = answer2 
lead.LeadSource = "Other"; 
result = sforce.connection.create([lead]); 

var lid = result[0].id; 
var retURL; 
if (lid == null) { 
alert ("{!$User.FirstName} the lead insert failed for "+ answer1 +" "+ answer2 + ". Please try again."); 
retURL = "https://cs4.salesforce.com/" + "{!Account.Id}"; 
} 
else { 
alert ("{!$User.FirstName} a new lead has been created for "+ answer1 +" "+ answer2 ); 
retURL = "https://cs4.salesforce.com/" + lid; 
} 
window.location.href = retURL;

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Expert of the Year 2008
Top Expert 2008
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE