How to fix it
- 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.
- 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. - If in Service Portal, navigate to
Service Portal > Widgets, find your widget, and replace g_form references withg_formalternatives using the widget's server script or spUtil. - For Service Portal forms, use
c.datato access field values andc.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.
- 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. - For Client Scripts running outside form context, navigate to
System Definition > Client Scriptsand verify the Type field is set to onLoad, onChange, onSubmit, or onCellEdit. - 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. - For timing issues with onLoad scripts, wrap your g_form calls in
setTimeout(function() { /* g_form code */ }, 100);to ensure form initialization completes first. - 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. - 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.