Help with Modal on sc_task form in platform with Next Experience enabled

Tamara11
Mega Sage

Greetings geniuses!

 

We have a catalog item with a workflow that requires fulfillers to answer a variable (mulitple choice: a question with 2 options presented as radio buttons) on their task form.  If they answer "yes," then we need a modal to pop up and display another (previously answered) multiple choice variable, a question with 3 options presented as radio buttons so they can change the value, and then save the fulfillers answer back to that variable.

This will happen on the sctask form, in the platform UI, wiht Next Experience enabled.

Is this possible?  I've gotten very close using a select box, but I really need it to present as a multiple choice.

 

I've tried so many variations, each using an onchange catalog client script, some using UI Pages, some using UI Macros, none working.  Because I've tried so many different variations, I'm not pasting my code here because I clearly don't know what I'm doing and don't want to steer the discussion in the wrong direction.

 

The only thing I'm *sure* of is that I can't use spmodal because this will not occur on the Service Portal. 

ChatGPT couldn't help, Grok, couldn't help, and Copilot couldn't help.

Hopefully someone here can help. 🥺

3 REPLIES 3

k_lutz
Tera Expert

Hi,

Not sure if this will help but here is some code I tried in our instance that had a modal appear. I did have some issues as we are testing Now Assist and it kept giving me errors on the onChange saying Virtual Agent will not like it...seems like SN may want to try to keep things simple so its easier to consume or present in VA when presenting catalog items. This does not include any code for pushing the values back and updating variables but having a model appear with radio options. Hope it may help.

Thank you so much for this, @k_lutz.

 

The UI page opens when I test it or when I browse to its .do url but the modal doesn't open when I answer the trigger question on the form.

I see an error in the browser console:

Spoiler
Uncaught TypeError: window is null
openKmlModal https://okstatedev.service-now.com/sc_task.do?sys_id=c75a22f93b16a6d051d1354a85e45ab4&sysparm_record...
h_08920a5afb9aa69054eafa656eefdc4c https://okstatedev.service-now.com/sc_task.do?sys_id=c75a22f93b16a6d051d1354a85e45ab4&sysparm_record...
doCatOnChange https://okstatedev.service-now.com/scripts/js_includes_catalog.jsx?v=04-03-2025_0833&lp=Wed_Jun_11_0...
variableOnChange https://okstatedev.service-now.com/scripts/js_includes_catalog.jsx?v=04-03-2025_0833&lp=Wed_Jun_11_0...
<anonymous> https://okstatedev.service-now.com/sc_task.do?sys_id=c75a22f93b16a6d051d1354a85e45ab4&sysparm_record...
handleEvent https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
createResponder https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
observeStandardEvent https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
observe https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
start https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
on https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
_methodized https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
<anonymous> https://okstatedev.service-now.com/sc_task.do?sys_id=c75a22f93b16a6d051d1354a85e45ab4&sysparm_record...
runAfterAllLoaded https://okstatedev.service-now.com/scripts/doctype/js_includes_doctype.jsx?v=04-03-2025_0833&lp=Wed_...
<anonymous> https://okstatedev.service-now.com/scripts/doctype/z_last_include.jsx?v=04-03-2025_0833:34
<anonymous> https://okstatedev.service-now.com/scripts/doctype/z_last_include.jsx?v=04-03-2025_0833:39
sc_task.do:1432:1

I'll spend some more time with it and see if I can determine what I've done wrong but, it probably won't be until this weekend.  I'll post back if I'm successful.

Thanks again for your help. 🙂

You're welcome. I would first check that the "Isolate script" is unchecked on the client script. If that is checked it may not be firing the code. After that I would probably try the following as my example is one variable with no other logic happening...so might be a timing type of issue:

 

#1 try adding a safety check:
function openKmlModal() {
// Safety check for window object
if (typeof window === 'undefined' || !window) {
console.log('Window object not available');
return;
}

var url = '/kml_test_modal.do';
window.open(url, 'kmlModal', 'width=450,height=350,scrollbars=no,resizable=no');
}


#2 try using a timing check:
function openKmlModal() {
// Ensure window is available
setTimeout(function() {
if (window && window.open) {
var url = '/kml_test_modal.do';
window.open(url, 'kmlModal', 'width=450,height=350,scrollbars=no,resizable=no');
}
}, 100);
}

#3 try rewriting it to use glidemodal instead of the window version
Convert it to use new GlideModal