How to fix it

  1. First, identify where the error is occurring. Open browser developer tools (F12), go to Console tab, and look for the exact line throwing the g_form error.
  2. Check if you're in Service Portal by looking at the URL. If it contains /sp/ or /csm/, you're in Service Portal where g_form doesn't exist.
  3. If in Service Portal, navigate to Service Portal > Widgets, find your widget, and replace g_form references with g_form alternatives using the widget's server script or spUtil.
  4. For Service Portal forms, use c.data to access field values and c.server.update() to refresh the form instead of g_form methods.
⚠️

Never try to load g_form manually in Service Portal - it will break the widget architecture.

  1. If you need Classic UI, change the URL by removing /sp/ and replacing with /nav_to.do?uri= followed by the table and sys_id.
  2. For Client Scripts running outside form context, navigate to System Definition > Client Scripts and verify the Type field is set to onLoad, onChange, onSubmit, or onCellEdit.
  3. If the script is in a UI Action, go to System UI > UI Actions, find your action, and move g_form code to a Client Script instead, or use GlideRecord server-side logic.
  4. For timing issues with onLoad scripts, wrap your g_form calls in setTimeout(function() { /* g_form code */ }, 100); to ensure form initialization completes first.
  5. Add a safety check at the top of your Client Script: if (typeof g_form == 'undefined') { return; } to prevent errors when g_form isn't available.
  6. Test your fix by refreshing the form and checking the browser console for any remaining g_form errors.
💡

Quick test: Open browser console and type 'g_form' - if it returns 'undefined', you're not in Classic UI or not on a form.