Notifications

211 views

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/bundle/kingston-platform-administration/page/administer/currency/concept/currency-values-scripts.html

 - Documentation for the GlideForm API: https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideForm/concept/c_GlideFormAPI.html

Article Information

Last Updated:2018-08-03 02:24:02
Published:2018-07-13