I want to track how many times a user clicks on a certain button called Reject. So I created a counter field that will be updated whenever the Reject button is clicked. The counter I created is called Num_of_Rejects_Tier3__c and it's a field of type Number.

So here is a snippet of the onClick JavaScript button:

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';

I don't know why but I get the following error:

value outside of valid range on numeric field: NaN

What does it say that it isn't a number and how can it be resolved?


Yes, it is not a number because new Case instance doesn't have any value. I am not sure if Num_of_Rejects_Tier3__c will have any existing value based on existing logic. Try below logic where we are checking if value is a number or not.

var caseObj = new sforce.SObject("Case");
caseObj.Id = '{!Case.Id}';
caseObj.Num_of_Rejects_Tier3__c= (isNaN(caseObj.Num_of_Rejects_Tier3__c) ? 0 : caseObj.Num_of_Rejects_Tier3__c )+1;

Note that, because you are creating new Sobject record. So, Num_of_Rejects_Tier3__c won't have any value and initialized to null each time/click. You must update the records and query existing count to make it work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.