Error Reference

Data type mismatch: expected integer, got string

Data type mismatch: expected integer, got string

Where this appears

This error appears in the ServiceNow system logs, application logs, or browser console when server-side scripts attempt to assign string values to integer-type fields. It commonly occurs during GlideRecord operations, Business Rule execution, or Transform Map processing when field type validation fails.

Sourdough
Chrome Extension

Debugging this in a real instance?

Sourdough lets you trace "Data type mismatch: expected integer, got string" through system logs, script errors, and API health in the ServiceNow tab you are already using.

Add to Chrome

Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.

Overview
Tasks
CMDB
API
Metrics
Monitor
Internals
Instance:sourdoughdev·Version:Yokohama
Instance StateONLINE
System StatusFully Operational
Session Timeout90 minutes
Logged-In Sessions2 (20 active)
Build Nameyokohama-12-18-2024_p1
IP Address10.159.128.43
Instance HealthHealth Score: 90%
🔥 5dSourdough (Chrome Plugin)Dark Mode

Cause

A script directly assigns a string value to a GlideRecord field that expects an integer, such as setting gr.number_field = 'text' instead of gr.number_field = 123. (high likelihood)

User input from forms or REST API calls contains non-numeric characters that are passed to integer fields without proper validation or conversion. (high likelihood)

Transform Maps are configured to map string source values directly to integer destination fields without field mapping scripts or coercion rules. (medium likelihood)

JavaScript variables contain unexpected string values due to incorrect data retrieval or manipulation before being assigned to integer GlideRecord fields. (medium likelihood)

Custom UI actions or client scripts pass form field values as strings to server-side functions that expect numeric parameters for database operations. (low likelihood)

Fix

Step 1: Check the System Log at System Diagnostics > Log Files > Node Log File to identify the exact script file and line number where the error occurs.

Step 2: Navigate to the problematic script (Business Rule, Script Include, or Transform Map) and locate the line that assigns values to integer fields.

Step 3: Examine the source of the data being assigned and verify what type of value it contains using typeof operator or gs.log() statements for debugging.

Step 4: Convert string values to integers using parseInt(), parseFloat(), or Number() functions before assignment, ensuring proper validation for non-numeric input.

Step 5: Add input validation to check if the value is numeric using isNaN() function and handle cases where conversion fails with appropriate error handling.

Step 6: For Transform Maps, configure Field Maps with appropriate scripting to handle data type conversion or use the Advanced tab for complex transformations.

Step 7: Test the fix by reproducing the original conditions that triggered the error and verify that integer fields now receive properly formatted numeric values.

Step 8: Monitor the System Log for 24-48 hours after deployment to ensure the error no longer appears and no new related issues have emerged.

Test Your Knowledge

Quick 3-question quiz. See how your ServiceNow skills stack up.

Question 1 of 3Performance

A list view on a table with millions of records is slow. Best fix?

Select an answer to continue