Not able to pass data from UI page to workspace client script.

gurdesi2
Tera Contributor

While working on UI page, I want to pass data from UI page client script to my actual Interaction record client script where I'm using g_modal.showframe and a callback function to retrieve values.

 

Tried using iframeMSGHelper and Window.parent.postMessage but both are not working. Help with a solution please.

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@gurdesi2 

see this

Solved: How to pass data from client script to workspace U... - ServiceNow Community

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Hi Ankur, 

 

Thanks for the reply, but seems like this solution may work on native but for Workspace its not working.

sanjaygupta
Tera Guru

Both of your attempts are close. The g_modal.showFrame() callback only fires when the UI page sends a message in the exact format the parent expects, and a plain window.parent.postMessage with custom data is ignored. That is why confirmed comes back false. The community’s working pattern sends a message of type IFRAME_MODAL_ACTION_CONFIRMED with the modal’s ID. iframeMsgHelper is an internal helper used in some out-of-box pages, so I can’t confirm it is documented or stable across releases. The community wrapped it as a reusable UI Script called iframeHelper.

Note that GlideModal is a Classic UI API and doesn’t work in Workspace.

  • Read the out-of-box UI page time_sheet_recall_dialogue and the Recall UI action on the time_card table. They show the working pattern.
  • In your UI page client script, run iframeHelper.confirm({ your_field: value }) on the Submit button click, not on page load.
  • In your Interaction client script, open the modal with g_modal.showFrame({ url: 'your_ui_page.do', title: 'Your title', size: 'md', callback: function(confirmed, data) { ... } }).
  • In the callback, check confirmed first, then read your values from data.
  • If it still returns false, check the browser console for errors.
  • Make sure the frame loads your UI page and not a login or error page.
  • Remove any custom window.parent.postMessage call running alongside the helper.

If the modal won’t close, window.top.g_modal.destroy() often fails in Workspace. Keep the reference returned by g_modal.showFrame() instead. For a simple Yes/No, g_modal.confirm() is easier and more reliable.

Test in a sub-production instance first, and keep changes in an update set or scoped app.

Your Workspace type, release, and whether the script runs from a UI action or an onChange client script would help me narrow this down.

Sources: