Avatar of -Dman100-
Flag for United States of America

asked on 

number outside valid range

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.

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


Avatar of undefined
Last Comment

8/22/2022 - Mon