The CreatorCon Call for Content is officially open! Get started here.

Migrating a UI Page to work in Workspace when triggered from an onChange client script?

Roger11
Giga Guru

We have a really simple UI Page that asks the user a question and they click either YES or NO.
From the HTML section of the UI Page

Roger11_0-1731387583801.png

The client script is pretty simple and it works fine in Classic UI

Roger11_1-1731387643787.png

This is the client script that launches the UI Page. It works for both Classic UI and Workspace - however, no idea what needs to change to get back whether the user clicked Yes or No. Looking at this page, they haven't provided a clear outline of all the moving parts and where they live. I've tried cutting pasting all the IFrameHelper code into the client script on the UI page but that doesn't work.

Roger11_3-1731388312087.png

I can't be far from something that works - but that 5 minute piece of work is running into hours now.

 

 

1 ACCEPTED SOLUTION

Roger11
Giga Guru
We solved this by using a g_modal.confirm in the end (from a servicenow staff member)
 
        var ga = new GlideAjax('ChangeUtilsAJAX');
        ga.addParam('sysparm_name', 'checkSomething');
        ga.addParam('sysparm_category', _category);
        ga.addParam('sysparm_ci', _ci);
        ga.getXMLAnswer(function(response) {
            if (!response.startsWith("X")) { 
                if (response.startsWith("H")) {
 
This tests if we're in Workspace or Classic UI
                    if (typeof g_ui_scripts != "undefined") {
Workspace Code
                        var msg = getMessage(disText);
                        g_modal.confirm(getMessage(disTitle), msg, function(confirmed) {
                            if (confirmed) {
                                g_form.setDisplay('u_something', true);
                                g_form.setValue('u_something', response);
                            } else {
                                g_form.clearValue('category');
                                return
                            }
                        });
                    } else {
Classic UI Code using a UI Page modal dialog
                        var dialog = new GlideModal('change_something', true, 600);
                        dialog.setTitle(disTitle);
                        dialog.render();
                    }
                }
                g_form.setDisplay('u_something', true);
                g_form.setValue('u_something', response);
            }
        });

View solution in original post

2 REPLIES 2

Roger11
Giga Guru

In the Agent Workspace UI Action examples link related to this, I tried

Roger11_0-1731395037723.png

but that goes straight to the "catch" in my try-catch block

Roger11
Giga Guru
We solved this by using a g_modal.confirm in the end (from a servicenow staff member)
 
        var ga = new GlideAjax('ChangeUtilsAJAX');
        ga.addParam('sysparm_name', 'checkSomething');
        ga.addParam('sysparm_category', _category);
        ga.addParam('sysparm_ci', _ci);
        ga.getXMLAnswer(function(response) {
            if (!response.startsWith("X")) { 
                if (response.startsWith("H")) {
 
This tests if we're in Workspace or Classic UI
                    if (typeof g_ui_scripts != "undefined") {
Workspace Code
                        var msg = getMessage(disText);
                        g_modal.confirm(getMessage(disTitle), msg, function(confirmed) {
                            if (confirmed) {
                                g_form.setDisplay('u_something', true);
                                g_form.setValue('u_something', response);
                            } else {
                                g_form.clearValue('category');
                                return
                            }
                        });
                    } else {
Classic UI Code using a UI Page modal dialog
                        var dialog = new GlideModal('change_something', true, 600);
                        dialog.setTitle(disTitle);
                        dialog.render();
                    }
                }
                g_form.setDisplay('u_something', true);
                g_form.setValue('u_something', response);
            }
        });