Issue
Symptoms
When using g_form.setValue() to change the value for a Currency field and error message is thrown in the browser console with the following message:
"TypeError: value.indexOf is not a function"
Cause
Documentation for the GlideForm API states the setValue() function takes two string parameters, the field name and the value being assigned:
setValue(string field_name, string value)
It is most likely the case that the 'value' being passed to the setValue function is not a string.
Resolution
Make sure the value you are trying to set as the value is converted to a string type before passing it to the setValue() function.
Ex: g_form.setValue('field_name', parseFloat(5.34).toString());
Ex: g_form.setValue('field_name', String(5.34));
Additional Information
- Documentation on scripting with Currency fields: https://docs.servicenow.com/csh?topicname=currency-values-scripts.html&version=latest
- Documentation for the GlideForm API: https://docs.servicenow.com/csh?topicname=c_GlideFormAPI.html&version=latest