ATF - FAILURE: g_form is not defined. A valid form must have g_form defined

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2019 11:36 PM
Have anybody found a solution for this error
FAILURE: g_form is not defined. A valid form must have g_form defined
I am getting this error in the test step "Open a Form (SP)". I open a custom portal with a custom page that contains 3 custom widgets.
I have tried to setup g_form with code like this
$scope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
g_form = gFormInstance;
}
but the event spModel.gForm.initialized is never fired.
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2019 08:13 AM
Hmmm. How do you go about cloning that step configuration?
There is no clone option and it is not possible to do an insert due to unique value constraint.
And it is not possible to create the same step manually because only people with the "maint" role can set the step environment to "UI".
So back to square one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2019 11:24 AM
I agree, that it's a little tricky, because of some default implementations in ATF.
The first problem with UI environment can be solved in very easy way. You need just open "Configure Dictionary" of "Step environment" field
and remove condition, which prevents to choose UI environment:
After that you will be able to choose UI environment.
The next problem: you need to create input variables for the step. If you will create the Test Configuration Step in Global scope (instead of usage scope application) then the variables get "u_" prefix. You should use the fact in scripts and use the corresponding names of variables in the code.
Finally, after some tests I found, that the reference variables will be initialized as strings instead of GlideRecord objects. I mean that you will get variables like step.inputs.u_portal as sys_id of portal. Thus you can't just use step.inputs.u_portal.url_suffix. One have to open the corresponding GlideRecord by sys_id and only then one will be able to use url_suffix property.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2019 09:46 PM
I already tried that and it is not enough. There is a business rule that prevents save of the step if step environment is set to UI and that BR is also read only.
Anyway this is too much hacking of oob functionality. The missing g_form must be solved in a different way. Thanks for the answers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 02:16 PM
Sorry, for the delay. I found today a little time for your problem.
I agree, that hacking isn't the best way, but I see no standard alternatives to solve the problem. ServiceNow don't provide any way to open custom page with custom widgets, which don't use GlideGrid.
We had close problem and solved it by creating (with hacking) of custom Step Configuration, which works in UI environment. To do that I did the following steps:
1) created new record in "Test Step Config" [sys_atf_step_config] table with "Server - Independent" as "Step environment" and no Category.
2) exported the record as XML
3) replaced the line
<step_env display_value="Server - Independent">6c2bcea1870312009dccc9ded0e3ecca</step_env>
to
<step_env display_value="UI">d2cb02e1870312009dccc9ded0e3ec7c</step_env>
4) imported the XML file. The imported Test Step had UI in "Step environment". It hold the value during all other modifications of the test step.
5) set "Service Portal" as category of the step.
6) replaced "Step execution script" created initially. It's important to understand, that scripts for UI environments has another parameters (global step, stepResult and assertionObject). You can copy the code from another config steps (for example "Open a Form (SP)").
It's important to replace ensureGform to your custom callback function, which test existence of your custom widgets. I used g_ui_testing_util.getTestIFrameWindow().$ in my code to find elements used in our custom widget. Mostly the callback will be first called before child widgets are created on the page. Thus the usage of setTimeout or setInterval really important.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2019 09:29 AM
Is the problem solved? Could you create custom Step Configuration, which works in UI environment and which opens your custom UI Page in Service Portal? You can export "Open Service Portal Page" step from a New York instance and use on Madrid, but I personally find the code of the ensurePageIsLoaded function (analog of ensureGform) not good for common case because it doesn't wait for loading of some custom widgets on the page. I described shortly my implementation in previous post. If needed I can post you the corresponding JavaScript code.