Issue
The use of the "g_form" as a global object and its functions such as setValue(), getValue(), and setMandatory() are not working as expected when they are used in a service portal widget's client controller field.
Cause
"g_form" as a global object cannot be used in a widget client controller so its functions are not supported either.
Please refer to the following documentation for this information: Widget API reference.
Resolution
Avoid using "g_form" as a global object and its associated functions directly in the widget's client controller and instead, use alternatives such as (catalog) UI policies and/or (catalog) Client Scripts to affect variables/fields.
It is, however, still possible to make use of "g_form" and its supported functions in the widget client controller through the use of a variable type Macro and embedded widget.
See the following documentation on how to use it: Replace a Service Catalog form script with a widget.